providers/aws: Fix S3 website error doc

This commit is contained in:
Justin Campbell 2015-05-06 08:40:32 -04:00
parent 0b78a71ed5
commit 87e6d3d17f
2 changed files with 36 additions and 6 deletions

View File

@ -129,10 +129,15 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
})
var websites []map[string]interface{}
if err == nil {
websites = append(websites, map[string]interface{}{
"index_document": *ws.IndexDocument.Suffix,
"error_document": *ws.ErrorDocument.Key,
})
w := make(map[string]interface{})
w["index_document"] = *ws.IndexDocument.Suffix
if v := ws.ErrorDocument; v != nil {
w["error_document"] = *v.Key
}
websites = append(websites, w)
}
if err := d.Set("website", websites); err != nil {
return err

View File

@ -37,6 +37,14 @@ func TestAccAWSS3BucketWebsite(t *testing.T) {
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSS3BucketWebsiteConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketWebsite(
"aws_s3_bucket.bucket", "index.html", ""),
),
},
resource.TestStep{
Config: testAccAWSS3BucketWebsiteConfigWithError,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3BucketWebsite(
@ -118,9 +126,15 @@ func testAccCheckAWSS3BucketWebsite(n string, indexDoc string, errorDoc string)
return fmt.Errorf("bad: %s", out.IndexDocument)
}
if *out.ErrorDocument.Key != errorDoc {
if v := out.ErrorDocument; v == nil {
if errorDoc != "" {
return fmt.Errorf("bad: %s", out.ErrorDocument)
}
} else {
if *v.Key != errorDoc {
return fmt.Errorf("bad: %s", out.ErrorDocument)
}
}
return nil
}
@ -141,6 +155,17 @@ resource "aws_s3_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
acl = "public-read"
website {
index_document = "index.html"
}
}
`, d)
var testAccAWSS3BucketWebsiteConfigWithError = fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
bucket = "tf-test-bucket-%d"
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"