From 8129c0589cc85879752173585ce3245ab26abe01 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 5 May 2016 15:44:35 -0500 Subject: [PATCH] provider/aws: Require cookies for Cloudfront Distributions --- .../aws/cloudfront_distribution_configuration_structure.go | 4 ++-- .../providers/aws/resource_aws_cloudfront_distribution.go | 2 +- .../providers/aws/r/cloudfront_distribution.html.markdown | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go index 45338e7f4..67baf9fb3 100644 --- a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go +++ b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go @@ -358,7 +358,7 @@ func expandForwardedValues(m map[string]interface{}) *cloudfront.ForwardedValues fv := &cloudfront.ForwardedValues{ QueryString: aws.Bool(m["query_string"].(bool)), } - if v, ok := m["cookies"]; ok { + if v, ok := m["cookies"]; ok && v.(*schema.Set).Len() > 0 { fv.Cookies = expandCookiePreference(v.(*schema.Set).List()[0].(map[string]interface{})) } if v, ok := m["headers"]; ok { @@ -385,7 +385,7 @@ func forwardedValuesHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) buf.WriteString(fmt.Sprintf("%t-", m["query_string"].(bool))) - if d, ok := m["cookies"]; ok { + if d, ok := m["cookies"]; ok && d.(*schema.Set).Len() > 0 { buf.WriteString(fmt.Sprintf("%d-", cookiePreferenceHash(d.(*schema.Set).List()[0].(map[string]interface{})))) } if d, ok := m["headers"]; ok { diff --git a/builtin/providers/aws/resource_aws_cloudfront_distribution.go b/builtin/providers/aws/resource_aws_cloudfront_distribution.go index 23c422524..2ace7dc24 100644 --- a/builtin/providers/aws/resource_aws_cloudfront_distribution.go +++ b/builtin/providers/aws/resource_aws_cloudfront_distribution.go @@ -58,7 +58,7 @@ func resourceAwsCloudFrontDistribution() *schema.Resource { Schema: map[string]*schema.Schema{ "cookies": &schema.Schema{ Type: schema.TypeSet, - Optional: true, + Required: true, Set: cookiePreferenceHash, MaxItems: 1, Elem: &schema.Resource{ diff --git a/website/source/docs/providers/aws/r/cloudfront_distribution.html.markdown b/website/source/docs/providers/aws/r/cloudfront_distribution.html.markdown index 8bfa53c7d..7fa6b4454 100644 --- a/website/source/docs/providers/aws/r/cloudfront_distribution.html.markdown +++ b/website/source/docs/providers/aws/r/cloudfront_distribution.html.markdown @@ -186,7 +186,7 @@ of several sub-resources - these resources are laid out below. ##### Forwarded Values Arguments - * `cookies` (Optional) - The [forwarded values cookies](#cookies-arguments) + * `cookies` (Required) - The [forwarded values cookies](#cookies-arguments) that specifies how CloudFront handles cookies (maximum one). * `headers` (Optional) - Specifies the Headers, if any, that you want @@ -200,7 +200,8 @@ of several sub-resources - these resources are laid out below. * `forward` (Required) - Specifies whether you want CloudFront to forward cookies to the origin that is associated with this cache behavior. You can - specify `all`, `none` or `whitelist`. + specify `all`, `none` or `whitelist`. If `whitelist`, you must include the + subsequent `whitelisted_names` * `whitelisted_names` (Optional) - If you have specified `whitelist` to `forward`, the whitelisted cookies that you want CloudFront to forward to