diff --git a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go index ccac0d9c5..489e9883c 100644 --- a/builtin/providers/aws/cloudfront_distribution_configuration_structure.go +++ b/builtin/providers/aws/cloudfront_distribution_configuration_structure.go @@ -443,10 +443,10 @@ func expandLambdaFunctionAssociation(lf map[string]interface{}) *cloudfront.Lamb return &lfa } -func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) []interface{} { - s := make([]interface{}, len(lfa.Items)) - for i, v := range lfa.Items { - s[i] = flattenLambdaFunctionAssociation(v) +func flattenLambdaFunctionAssociations(lfa *cloudfront.LambdaFunctionAssociations) *schema.Set { + s := schema.NewSet(lambdaFunctionAssociationHash, []interface{}{}) + for _, v := range lfa.Items { + s.Add(flattenLambdaFunctionAssociation(v)) } return s } diff --git a/builtin/providers/aws/cloudfront_distribution_configuration_structure_test.go b/builtin/providers/aws/cloudfront_distribution_configuration_structure_test.go index 14cdad322..0092cb8d2 100644 --- a/builtin/providers/aws/cloudfront_distribution_configuration_structure_test.go +++ b/builtin/providers/aws/cloudfront_distribution_configuration_structure_test.go @@ -364,14 +364,8 @@ func TestCloudFrontStructure_flattenCacheBehavior(t *testing.T) { t.Fatalf("Expected out[target_origin_id] to be myS3Origin, got %v", out["target_origin_id"]) } - // the flattened lambda function associations are a slice of maps, - // where as the default cache behavior LFAs are a set. Here we double check - // that and conver the slice to a set, and use Set's Equal() method to check - // equality - var outSet *schema.Set - if outSlice, ok := out["lambda_function_association"].([]interface{}); ok { - outSet = schema.NewSet(lambdaFunctionAssociationHash, outSlice) - } else { + var outSet, ok = out["lambda_function_association"].(*schema.Set) + if !ok { t.Fatalf("out['lambda_function_association'] is not a slice as expected: %#v", out["lambda_function_association"]) } @@ -496,7 +490,7 @@ func TestCloudFrontStructure_flattenlambdaFunctionAssociations(t *testing.T) { lfa := expandLambdaFunctionAssociations(in.List()) out := flattenLambdaFunctionAssociations(lfa) - if reflect.DeepEqual(in.List(), out) != true { + if reflect.DeepEqual(in.List(), out.List()) != true { t.Fatalf("Expected out to be %v, got %v", in, out) } }