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

r/aws_cloudfront_distribution: Fix aws_cloudfront_distribution import plus failing acceptance test #14844

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
42 changes: 21 additions & 21 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ func flattenCloudFrontDefaultCacheBehavior(dcb *cloudfront.DefaultCacheBehavior)
func flattenCacheBehavior(cb *cloudfront.CacheBehavior) map[string]interface{} {
m := make(map[string]interface{})

m["compress"] = *cb.Compress
m["compress"] = aws.BoolValue(cb.Compress)
m["field_level_encryption_id"] = aws.StringValue(cb.FieldLevelEncryptionId)
m["viewer_protocol_policy"] = *cb.ViewerProtocolPolicy
m["target_origin_id"] = *cb.TargetOriginId
m["viewer_protocol_policy"] = aws.StringValue(cb.ViewerProtocolPolicy)
m["target_origin_id"] = aws.StringValue(cb.TargetOriginId)
m["forwarded_values"] = []interface{}{flattenForwardedValues(cb.ForwardedValues)}
m["min_ttl"] = int(*cb.MinTTL)
m["min_ttl"] = int(aws.Int64Value(cb.MinTTL))

if len(cb.TrustedSigners.Items) > 0 {
m["trusted_signers"] = flattenTrustedSigners(cb.TrustedSigners)
Expand Down Expand Up @@ -402,9 +402,9 @@ func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociation
func flattenLambdaFunctionAssociation(lfa *cloudfront.LambdaFunctionAssociation) map[string]interface{} {
m := map[string]interface{}{}
if lfa != nil {
m["event_type"] = *lfa.EventType
m["lambda_arn"] = *lfa.LambdaFunctionARN
m["include_body"] = *lfa.IncludeBody
m["event_type"] = aws.StringValue(lfa.EventType)
m["lambda_arn"] = aws.StringValue(lfa.LambdaFunctionARN)
m["include_body"] = aws.BoolValue(lfa.IncludeBody)
}
return m
}
Expand All @@ -427,7 +427,7 @@ func expandForwardedValues(m map[string]interface{}) *cloudfront.ForwardedValues

func flattenForwardedValues(fv *cloudfront.ForwardedValues) map[string]interface{} {
m := make(map[string]interface{})
m["query_string"] = *fv.QueryString
m["query_string"] = aws.BoolValue(fv.QueryString)
if fv.Cookies != nil {
m["cookies"] = []interface{}{flattenCookiePreference(fv.Cookies)}
}
Expand Down Expand Up @@ -480,7 +480,7 @@ func expandCookiePreference(m map[string]interface{}) *cloudfront.CookiePreferen

func flattenCookiePreference(cp *cloudfront.CookiePreference) map[string]interface{} {
m := make(map[string]interface{})
m["forward"] = *cp.Forward
m["forward"] = aws.StringValue(cp.Forward)
if cp.WhitelistedNames != nil {
m["whitelisted_names"] = schema.NewSet(schema.HashString, flattenCookieNames(cp.WhitelistedNames))
}
Expand Down Expand Up @@ -636,7 +636,7 @@ func expandOriginGroup(m map[string]interface{}) *cloudfront.OriginGroup {

func flattenOriginGroup(og *cloudfront.OriginGroup) map[string]interface{} {
m := make(map[string]interface{})
m["origin_id"] = *og.Id
m["origin_id"] = aws.StringValue(og.Id)
if og.FailoverCriteria != nil {
m["failover_criteria"] = flattenOriginGroupFailoverCriteria(og.FailoverCriteria)
}
Expand Down Expand Up @@ -666,7 +666,7 @@ func flattenOriginGroupFailoverCriteria(ogfc *cloudfront.OriginGroupFailoverCrit
if ogfc.StatusCodes.Items != nil {
l := []interface{}{}
for _, i := range ogfc.StatusCodes.Items {
l = append(l, int(*i))
l = append(l, int(aws.Int64Value(i)))
}
m["status_codes"] = schema.NewSet(schema.HashInt, l)
}
Expand All @@ -693,7 +693,7 @@ func flattenOriginGroupMembers(ogm *cloudfront.OriginGroupMembers) []interface{}
s := []interface{}{}
for _, i := range ogm.Items {
m := map[string]interface{}{
"origin_id": *i.OriginId,
"origin_id": aws.StringValue(i.OriginId),
}
s = append(s, m)
}
Expand Down Expand Up @@ -794,8 +794,8 @@ func expandOriginCustomHeader(m map[string]interface{}) *cloudfront.OriginCustom

func flattenOriginCustomHeader(och *cloudfront.OriginCustomHeader) map[string]interface{} {
return map[string]interface{}{
"name": *och.HeaderName,
"value": *och.HeaderValue,
"name": aws.StringValue(och.HeaderName),
"value": aws.StringValue(och.HeaderValue),
}
}

Expand Down Expand Up @@ -836,12 +836,12 @@ func expandCustomOriginConfig(m map[string]interface{}) *cloudfront.CustomOrigin
func flattenCustomOriginConfig(cor *cloudfront.CustomOriginConfig) map[string]interface{} {

customOrigin := map[string]interface{}{
"origin_protocol_policy": *cor.OriginProtocolPolicy,
"http_port": int(*cor.HTTPPort),
"https_port": int(*cor.HTTPSPort),
"origin_protocol_policy": aws.StringValue(cor.OriginProtocolPolicy),
"http_port": int(aws.Int64Value(cor.HTTPPort)),
"https_port": int(aws.Int64Value(cor.HTTPSPort)),
"origin_ssl_protocols": flattenCustomOriginConfigSSL(cor.OriginSslProtocols),
"origin_read_timeout": int(*cor.OriginReadTimeout),
"origin_keepalive_timeout": int(*cor.OriginKeepaliveTimeout),
"origin_read_timeout": int(aws.Int64Value(cor.OriginReadTimeout)),
"origin_keepalive_timeout": int(aws.Int64Value(cor.OriginKeepaliveTimeout)),
}

return customOrigin
Expand Down Expand Up @@ -884,7 +884,7 @@ func expandS3OriginConfig(m map[string]interface{}) *cloudfront.S3OriginConfig {

func flattenS3OriginConfig(s3o *cloudfront.S3OriginConfig) map[string]interface{} {
return map[string]interface{}{
"origin_access_identity": *s3o.OriginAccessIdentity,
"origin_access_identity": aws.StringValue(s3o.OriginAccessIdentity),
}
}

Expand Down Expand Up @@ -939,7 +939,7 @@ func expandCustomErrorResponse(m map[string]interface{}) *cloudfront.CustomError

func flattenCustomErrorResponse(er *cloudfront.CustomErrorResponse) map[string]interface{} {
m := make(map[string]interface{})
m["error_code"] = int(*er.ErrorCode)
m["error_code"] = int(aws.Int64Value(er.ErrorCode))
if er.ErrorCachingMinTTL != nil {
m["error_caching_min_ttl"] = int(*er.ErrorCachingMinTTL)
}
Expand Down
20 changes: 10 additions & 10 deletions aws/resource_aws_cloudfront_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,17 +1092,17 @@ func TestAccAWSCloudFrontDistribution_OriginGroups(t *testing.T) {
testAccCheckCloudFrontDistributionExists(resourceName, &distribution),
resource.TestCheckResourceAttr(resourceName, "origin_group.#", "1"),
tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "origin_group.*", map[string]string{
"origin_id": "groupS3",
"failover_criteria.#": "1",
"failover_criteria.0.status_codes.#": "4",
"failover_criteria.0.status_codes.1057413486": "403",
"failover_criteria.0.status_codes.1883721641": "404",
"failover_criteria.0.status_codes.2661388106": "502",
"failover_criteria.0.status_codes.2895637960": "500",
"member.#": "2",
"member.0.origin_id": "primaryS3",
"member.1.origin_id": "failoverS3",
"origin_id": "groupS3",
"failover_criteria.#": "1",
"failover_criteria.0.status_codes.#": "4",
"member.#": "2",
"member.0.origin_id": "primaryS3",
"member.1.origin_id": "failoverS3",
}),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "origin_group.*.failover_criteria.0.status_codes.*", "403"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "origin_group.*.failover_criteria.0.status_codes.*", "404"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "origin_group.*.failover_criteria.0.status_codes.*", "500"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "origin_group.*.failover_criteria.0.status_codes.*", "502"),
),
},
},
Expand Down