From c58892485bdb74aceaa33689b186117532c4ffd5 Mon Sep 17 00:00:00 2001 From: Clint Date: Thu, 5 May 2016 10:49:09 -0500 Subject: [PATCH] provider/aws: Allow empty S3 config in Cloudfront Origin (#6487) * provider/aws: Allow empty S3 config in Cloudfront Origin --- ...oudfront_distribution_configuration_structure.go | 13 ++++++++++++- .../resource_aws_cloudfront_distribution_test.go | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go index dfd86e211..45338e7f4 100644 --- a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go +++ b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go @@ -527,6 +527,15 @@ func expandOrigin(m map[string]interface{}) *cloudfront.Origin { origin.S3OriginConfig = expandS3OriginConfig(s[0].(map[string]interface{})) } } + + // if both custom and s3 origin are missing, add an empty s3 origin + // One or the other must be specified, but the S3 origin can be "empty" + if origin.S3OriginConfig == nil && origin.CustomOriginConfig == nil { + origin.S3OriginConfig = &cloudfront.S3OriginConfig{ + OriginAccessIdentity: aws.String(""), + } + } + return origin } @@ -544,7 +553,9 @@ func flattenOrigin(or *cloudfront.Origin) map[string]interface{} { m["origin_path"] = *or.OriginPath } if or.S3OriginConfig != nil { - m["s3_origin_config"] = schema.NewSet(s3OriginConfigHash, []interface{}{flattenS3OriginConfig(or.S3OriginConfig)}) + if or.S3OriginConfig.OriginAccessIdentity != nil && *or.S3OriginConfig.OriginAccessIdentity != "" { + m["s3_origin_config"] = schema.NewSet(s3OriginConfigHash, []interface{}{flattenS3OriginConfig(or.S3OriginConfig)}) + } } return m } diff --git a/builtin/providers/aws/resource_aws_cloudfront_distribution_test.go b/builtin/providers/aws/resource_aws_cloudfront_distribution_test.go index 477a92115..b60ebeb57 100644 --- a/builtin/providers/aws/resource_aws_cloudfront_distribution_test.go +++ b/builtin/providers/aws/resource_aws_cloudfront_distribution_test.go @@ -195,7 +195,6 @@ resource "aws_cloudfront_distribution" "s3_distribution" { origin { domain_name = "${aws_s3_bucket.s3_bucket.id}" origin_id = "myS3Origin" - s3_origin_config {} } enabled = true default_root_object = "index.html" @@ -303,7 +302,6 @@ resource "aws_cloudfront_distribution" "multi_origin_distribution" { origin { domain_name = "${aws_s3_bucket.s3_bucket.id}" origin_id = "myS3Origin" - s3_origin_config {} } origin { domain_name = "www.example.com"