Skip to content

Commit

Permalink
providers/aws: Add S3 error_document
Browse files Browse the repository at this point in the history
Also fix when index/error document is empty
  • Loading branch information
justincampbell committed Apr 30, 2015
1 parent 0d9d444 commit 15f6ed0
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func resourceAwsS3Bucket() *schema.Resource {
ForceNew: false,
},

"error_document": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: false,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -141,20 +147,27 @@ func updateWebsite(s3conn *s3.S3, d *schema.ResourceData) error {
website := d.Get("website").(bool)
bucket := d.Get("bucket").(string)
indexDocument := d.Get("index_document").(string)

websiteConfiguration := &s3.WebsiteConfiguration{
IndexDocument: &s3.IndexDocument{Suffix: aws.String(indexDocument)},
}
errorDocument := d.Get("error_document").(string)

if website {
input := &s3.PutBucketWebsiteInput{
websiteConfiguration := &s3.WebsiteConfiguration{}

if indexDocument != "" {
websiteConfiguration.IndexDocument = &s3.IndexDocument{Suffix: aws.String(indexDocument)}
}

if errorDocument != "" {
websiteConfiguration.ErrorDocument = &s3.ErrorDocument{Key: aws.String(errorDocument)}
}

putInput := &s3.PutBucketWebsiteInput{
Bucket: aws.String(bucket),
WebsiteConfiguration: websiteConfiguration,
}

log.Printf("[DEBUG] S3 put bucket website: %s", input)
log.Printf("[DEBUG] S3 put bucket website: %s", putInput)

_, err := s3conn.PutBucketWebsite(input)
_, err := s3conn.PutBucketWebsite(putInput)
if err != nil {
return fmt.Errorf("Error putting S3 website: %s", err)
}
Expand Down

0 comments on commit 15f6ed0

Please sign in to comment.