Merge pull request #6505 from hashicorp/b-cloudfront-cookies

provider/aws: Require cookies for Cloudfront Distributions
This commit is contained in:
James Nugent 2016-05-08 19:45:37 -04:00
commit affd2b3f3b
3 changed files with 6 additions and 5 deletions

View File

@ -363,7 +363,7 @@ func expandForwardedValues(m map[string]interface{}) *cloudfront.ForwardedValues
fv := &cloudfront.ForwardedValues{ fv := &cloudfront.ForwardedValues{
QueryString: aws.Bool(m["query_string"].(bool)), 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{})) fv.Cookies = expandCookiePreference(v.(*schema.Set).List()[0].(map[string]interface{}))
} }
if v, ok := m["headers"]; ok { if v, ok := m["headers"]; ok {
@ -390,7 +390,7 @@ func forwardedValuesHash(v interface{}) int {
var buf bytes.Buffer var buf bytes.Buffer
m := v.(map[string]interface{}) m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%t-", m["query_string"].(bool))) 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{})))) buf.WriteString(fmt.Sprintf("%d-", cookiePreferenceHash(d.(*schema.Set).List()[0].(map[string]interface{}))))
} }
if d, ok := m["headers"]; ok { if d, ok := m["headers"]; ok {

View File

@ -58,7 +58,7 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"cookies": &schema.Schema{ "cookies": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Required: true,
Set: cookiePreferenceHash, Set: cookiePreferenceHash,
MaxItems: 1, MaxItems: 1,
Elem: &schema.Resource{ Elem: &schema.Resource{

View File

@ -186,7 +186,7 @@ of several sub-resources - these resources are laid out below.
##### Forwarded Values Arguments ##### 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). that specifies how CloudFront handles cookies (maximum one).
* `headers` (Optional) - Specifies the Headers, if any, that you want * `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 * `forward` (Required) - Specifies whether you want CloudFront to forward
cookies to the origin that is associated with this cache behavior. You can 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 * `whitelisted_names` (Optional) - If you have specified `whitelist` to
`forward`, the whitelisted cookies that you want CloudFront to forward to `forward`, the whitelisted cookies that you want CloudFront to forward to