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_cloudformation_stack: Fix perpetual diff on template with transform #9006

Merged
merged 1 commit into from
Dec 20, 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
3 changes: 2 additions & 1 deletion aws/resource_aws_cloudformation_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{}
}

tInput := cloudformation.GetTemplateInput{
StackName: aws.String(d.Id()),
StackName: aws.String(d.Id()),
TemplateStage: aws.String("Original"),
}
out, err := conn.GetTemplate(&tInput)
if err != nil {
Expand Down
81 changes: 81 additions & 0 deletions aws/resource_aws_cloudformation_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,32 @@ func TestAccAWSCloudFormationStack_withUrl_withParams_noUpdate(t *testing.T) {
})
}

func TestAccAWSCloudFormationStack_withTransform(t *testing.T) {
var stack cloudformation.Stack
rName := fmt.Sprintf("tf-acc-test-with-transform-%s", acctest.RandString(10))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCloudFormationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCloudFormationStackConfig_withTransform(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-transform", &stack),
),
},
{
PlanOnly: true,
Config: testAccAWSCloudFormationStackConfig_withTransform(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-transform", &stack),
),
},
},
})
}

func testAccCheckCloudFormationStackExists(n string, stack *cloudformation.Stack) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -710,3 +736,58 @@ resource "aws_cloudformation_stack" "with-url-and-params-and-yaml" {
}
`, rName, bucketKey, vpcCidr)
}

func testAccAWSCloudFormationStackConfig_withTransform(rName string) string {
return fmt.Sprintf(`
resource "aws_cloudformation_stack" "with-transform" {
name = "%[1]s"

template_body = <<STACK
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"Api": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "Prod",
"EndpointConfiguration": "REGIONAL",
"DefinitionBody": {
"swagger": "2.0",
"paths": {
"/": {
"get": {
"consumes": ["application/json"],
"produces": ["application/json"],
"responses": {
"200": {
"description": "200 response"
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"requestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"passthroughBehavior": "when_no_match",
"type": "mock"
}
}
}
}
}
}
}
}
}
STACK
capabilities = ["CAPABILITY_AUTO_EXPAND"]
on_failure = "DELETE"
timeout_in_minutes = 10
}
`, rName)
}