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

New Resources: aws_cloudformation_stack_set and aws_cloudformation_stack_set_instance #8020

Merged
merged 3 commits into from
Mar 21, 2019
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
18 changes: 18 additions & 0 deletions aws/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ func suppressAutoscalingGroupAvailabilityZoneDiffs(k, old, new string, d *schema
return false
}

func suppressCloudFormationTemplateBodyDiffs(k, old, new string, d *schema.ResourceData) bool {
normalizedOld, err := normalizeCloudFormationTemplate(old)

if err != nil {
log.Printf("[WARN] Unable to normalize Terraform state CloudFormation template body: %s", err)
return false
}

normalizedNew, err := normalizeCloudFormationTemplate(new)

if err != nil {
log.Printf("[WARN] Unable to normalize Terraform configuration CloudFormation template body: %s", err)
return false
}

return normalizedOld == normalizedNew
}

func suppressRoute53ZoneNameWithTrailingDot(k, old, new string, d *schema.ResourceData) bool {
// "." is different from "".
if old == "." || new == "." {
Expand Down
194 changes: 194 additions & 0 deletions aws/diff_suppress_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,200 @@ func TestSuppressEquivalentTypeStringBoolean(t *testing.T) {
}
}

func TestSuppressCloudFormationTemplateBodyDiffs(t *testing.T) {
testCases := []struct {
description string
equivalent bool
old string
new string
}{
{
description: `JSON no change`,
equivalent: true,
old: `
{
"Resources": {
"TestVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
}
},
"Outputs": {
"TestVpcID": {
"Value": { "Ref" : "TestVpc" }
}
}
}
`,
new: `
{
"Resources": {
"TestVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
}
},
"Outputs": {
"TestVpcID": {
"Value": { "Ref" : "TestVpc" }
}
}
}
`,
},
{
description: `JSON whitespace`,
equivalent: true,
old: `{"Resources":{"TestVpc":{"Type":"AWS::EC2::VPC","Properties":{"CidrBlock":"10.0.0.0/16"}}},"Outputs":{"TestVpcID":{"Value":{"Ref":"TestVpc"}}}}`,
new: `
{
"Resources": {
"TestVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
}
},
"Outputs": {
"TestVpcID": {
"Value": { "Ref" : "TestVpc" }
}
}
}
`,
},
{
description: `JSON change`,
equivalent: false,
old: `
{
"Resources": {
"TestVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
}
},
"Outputs": {
"TestVpcID": {
"Value": { "Ref" : "TestVpc" }
}
}
}
`,
new: `
{
"Resources": {
"TestVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "172.16.0.0/16"
}
}
},
"Outputs": {
"TestVpcID": {
"Value": { "Ref" : "TestVpc" }
}
}
}
`,
},
{
description: `YAML no change`,
equivalent: true,
old: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
Outputs:
TestVpcID:
Value: !Ref TestVpc
`,
new: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
Outputs:
TestVpcID:
Value: !Ref TestVpc
`,
},
{
description: `YAML whitespace`,
equivalent: false,
old: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16

Outputs:
TestVpcID:
Value: !Ref TestVpc

`,
new: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
Outputs:
TestVpcID:
Value: !Ref TestVpc
`,
},
{
description: `YAML change`,
equivalent: false,
old: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 172.16.0.0/16
Outputs:
TestVpcID:
Value: !Ref TestVpc
`,
new: `
Resources:
TestVpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
Outputs:
TestVpcID:
Value: !Ref TestVpc
`,
},
}

for _, tc := range testCases {
value := suppressCloudFormationTemplateBodyDiffs("test_property", tc.old, tc.new, nil)

if tc.equivalent && !value {
t.Fatalf("expected test case (%s) to be equivalent", tc.description)
}

if !tc.equivalent && value {
t.Fatalf("expected test case (%s) to not be equivalent", tc.description)
}
}
}

func TestSuppressRoute53ZoneNameWithTrailingDot(t *testing.T) {
testCases := []struct {
old string
Expand Down
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ func Provider() terraform.ResourceProvider {
"aws_budgets_budget": resourceAwsBudgetsBudget(),
"aws_cloud9_environment_ec2": resourceAwsCloud9EnvironmentEc2(),
"aws_cloudformation_stack": resourceAwsCloudFormationStack(),
"aws_cloudformation_stack_set": resourceAwsCloudFormationStackSet(),
"aws_cloudformation_stack_set_instance": resourceAwsCloudFormationStackSetInstance(),
"aws_cloudfront_distribution": resourceAwsCloudFrontDistribution(),
"aws_cloudfront_origin_access_identity": resourceAwsCloudFrontOriginAccessIdentity(),
"aws_cloudfront_public_key": resourceAwsCloudFrontPublicKey(),
Expand Down
Loading