From 0e46dae8c22f5809e4e7c84689167628217a65c9 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Wed, 20 Apr 2016 16:53:21 -0500 Subject: [PATCH] provider/aws: Fix crash in AWS S3 Bucket when website index/error is empty --- .../providers/aws/resource_aws_s3_bucket.go | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index e5d399cc9a12..2ec1c32e6560 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -871,7 +871,12 @@ func resourceAwsS3BucketWebsiteUpdate(s3conn *s3.S3, d *schema.ResourceData) err ws := d.Get("website").([]interface{}) if len(ws) == 1 { - w := ws[0].(map[string]interface{}) + var w map[string]interface{} + if ws[0] != nil { + w = ws[0].(map[string]interface{}) + } else { + w = make(map[string]interface{}) + } return resourceAwsS3BucketWebsitePut(s3conn, d, w) } else if len(ws) == 0 { return resourceAwsS3BucketWebsiteDelete(s3conn, d) @@ -883,10 +888,19 @@ func resourceAwsS3BucketWebsiteUpdate(s3conn *s3.S3, d *schema.ResourceData) err func resourceAwsS3BucketWebsitePut(s3conn *s3.S3, d *schema.ResourceData, website map[string]interface{}) error { bucket := d.Get("bucket").(string) - indexDocument := website["index_document"].(string) - errorDocument := website["error_document"].(string) - redirectAllRequestsTo := website["redirect_all_requests_to"].(string) - routingRules := website["routing_rules"].(string) + var indexDocument, errorDocument, redirectAllRequestsTo, routingRules string + if v, ok := website["index_document"]; ok { + indexDocument = v.(string) + } + if v, ok := website["error_document"]; ok { + errorDocument = v.(string) + } + if v, ok := website["redirect_all_requests_to"]; ok { + redirectAllRequestsTo = v.(string) + } + if v, ok := website["routing_rules"]; ok { + routingRules = v.(string) + } if indexDocument == "" && redirectAllRequestsTo == "" { return fmt.Errorf("Must specify either index_document or redirect_all_requests_to.")