Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_cloudfront_distribution: Add cache_behavior field_level_encryption_id attribute #4102

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func defaultCacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["target_origin_id"].(string)))
buf.WriteString(fmt.Sprintf("%d-", forwardedValuesHash(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{}))))
buf.WriteString(fmt.Sprintf("%d-", m["min_ttl"].(int)))
if d, ok := m["field_level_encryption_id"]; ok && d.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", d.(string)))
}
if d, ok := m["trusted_signers"]; ok {
for _, e := range sortInterfaceSlice(d.([]interface{})) {
buf.WriteString(fmt.Sprintf("%s-", e.(string)))
Expand Down Expand Up @@ -266,13 +269,14 @@ func flattenCacheBehaviors(cbs *cloudfront.CacheBehaviors) *schema.Set {

func expandCacheBehavior(m map[string]interface{}) *cloudfront.CacheBehavior {
cb := &cloudfront.CacheBehavior{
Compress: aws.Bool(m["compress"].(bool)),
ViewerProtocolPolicy: aws.String(m["viewer_protocol_policy"].(string)),
TargetOriginId: aws.String(m["target_origin_id"].(string)),
ForwardedValues: expandForwardedValues(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{})),
DefaultTTL: aws.Int64(int64(m["default_ttl"].(int))),
MaxTTL: aws.Int64(int64(m["max_ttl"].(int))),
MinTTL: aws.Int64(int64(m["min_ttl"].(int))),
Compress: aws.Bool(m["compress"].(bool)),
FieldLevelEncryptionId: aws.String(m["field_level_encryption_id"].(string)),
ViewerProtocolPolicy: aws.String(m["viewer_protocol_policy"].(string)),
TargetOriginId: aws.String(m["target_origin_id"].(string)),
ForwardedValues: expandForwardedValues(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{})),
DefaultTTL: aws.Int64(int64(m["default_ttl"].(int))),
MaxTTL: aws.Int64(int64(m["max_ttl"].(int))),
MinTTL: aws.Int64(int64(m["min_ttl"].(int))),
}

if v, ok := m["trusted_signers"]; ok {
Expand Down Expand Up @@ -304,6 +308,7 @@ func flattenCacheBehavior(cb *cloudfront.CacheBehavior) map[string]interface{} {
m := make(map[string]interface{})

m["compress"] = *cb.Compress
m["field_level_encryption_id"] = aws.StringValue(cb.FieldLevelEncryptionId)
m["viewer_protocol_policy"] = *cb.ViewerProtocolPolicy
m["target_origin_id"] = *cb.TargetOriginId
m["forwarded_values"] = schema.NewSet(forwardedValuesHash, []interface{}{flattenForwardedValues(cb.ForwardedValues)})
Expand Down Expand Up @@ -346,6 +351,9 @@ func cacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["target_origin_id"].(string)))
buf.WriteString(fmt.Sprintf("%d-", forwardedValuesHash(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{}))))
buf.WriteString(fmt.Sprintf("%d-", m["min_ttl"].(int)))
if d, ok := m["field_level_encryption_id"]; ok && d.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", d.(string)))
}
if d, ok := m["trusted_signers"]; ok {
for _, e := range sortInterfaceSlice(d.([]interface{})) {
buf.WriteString(fmt.Sprintf("%s-", e.(string)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func defaultCacheBehaviorConf() map[string]interface{} {
"allowed_methods": allowedMethodsConf(),
"cached_methods": cachedMethodsConf(),
"compress": true,
"field_level_encryption_id": "",
}
}

Expand Down
8 changes: 8 additions & 0 deletions aws/resource_aws_cloudfront_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Optional: true,
Default: 86400,
},
"field_level_encryption_id": {
Type: schema.TypeString,
Optional: true,
},
"forwarded_values": {
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -212,6 +216,10 @@ func resourceAwsCloudFrontDistribution() *schema.Resource {
Optional: true,
Default: 86400,
},
"field_level_encryption_id": {
Type: schema.TypeString,
Optional: true,
},
"forwarded_values": {
Type: schema.TypeSet,
Required: true,
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cloudfront_distribution.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ of several sub-resources - these resources are laid out below.
in the absence of an `Cache-Control max-age` or `Expires` header. Defaults to
1 day.

* `field_level_encryption_id` (Optional) - Field level encryption configuration ID

* `forwarded_values` (Required) - The [forwarded values configuration](#forwarded-values-arguments) that specifies how CloudFront
handles query strings, cookies and headers (maximum one).

Expand Down