From d107cb1e776c28765fc6b678cbd06bab22c332b5 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 25 Aug 2020 18:14:14 -0400 Subject: [PATCH 1/2] r/aws_cloudfront_distribution: Avoid raw pointer dereferences (#12992). --- ...nt_distribution_configuration_structure.go | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/aws/cloudfront_distribution_configuration_structure.go b/aws/cloudfront_distribution_configuration_structure.go index 5d94aee43ab..38610550683 100644 --- a/aws/cloudfront_distribution_configuration_structure.go +++ b/aws/cloudfront_distribution_configuration_structure.go @@ -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) @@ -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 } @@ -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)} } @@ -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)) } @@ -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) } @@ -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) } @@ -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) } @@ -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), } } @@ -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 @@ -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), } } @@ -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) } From 44c5ee39de1fcbe4cbea4462df27be2e32d8bbe8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 25 Aug 2020 18:36:17 -0400 Subject: [PATCH 2/2] r/aws_cloudfront_distribution: Fix 'TestAccAWSCloudFrontDistribution_OriginGroups'. --- ...source_aws_cloudfront_distribution_test.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_cloudfront_distribution_test.go b/aws/resource_aws_cloudfront_distribution_test.go index cd256a32daf..0353169c57a 100644 --- a/aws/resource_aws_cloudfront_distribution_test.go +++ b/aws/resource_aws_cloudfront_distribution_test.go @@ -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"), ), }, },