From 202b0aef1ba02f0beae945acc802adcd10073197 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 17 Dec 2015 17:01:31 +0100 Subject: [PATCH 1/2] provider/aws: Always use either body or URL for all updates - fixes #4332 --- .../providers/aws/resource_aws_cloudformation_stack.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack.go b/builtin/providers/aws/resource_aws_cloudformation_stack.go index 1846a3105..86dd8bdb7 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack.go @@ -258,12 +258,14 @@ func resourceAwsCloudFormationStackUpdate(d *schema.ResourceData, meta interface StackName: aws.String(d.Get("name").(string)), } - if d.HasChange("template_body") { - input.TemplateBody = aws.String(normalizeJson(d.Get("template_body").(string))) + // Either TemplateBody or TemplateURL are required for each change + if v, ok := d.GetOk("template_body"); ok { + input.TemplateBody = aws.String(normalizeJson(v.(string))) } - if d.HasChange("template_url") { - input.TemplateURL = aws.String(d.Get("template_url").(string)) + if v, ok := d.GetOk("template_url"); ok { + input.TemplateURL = aws.String(v.(string)) } + if d.HasChange("capabilities") { input.Capabilities = expandStringList(d.Get("capabilities").(*schema.Set).List()) } From 4e408d1593903e94a1fd2d2718909f6aed752890 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 17 Dec 2015 17:58:43 +0100 Subject: [PATCH 2/2] provider/aws: CloudFormation - Add regression test for #4332 --- .../resource_aws_cloudformation_stack_test.go | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go index 0c99f8d54..19b6f6c52 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go @@ -64,6 +64,31 @@ func TestAccAWSCloudFormation_allAttributes(t *testing.T) { }) } +// Regression for https://github.com/hashicorp/terraform/issues/4332 +func TestAccAWSCloudFormation_withParams(t *testing.T) { + var stack cloudformation.Stack + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudFormationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSCloudFormationConfig_withParams, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack), + ), + }, + resource.TestStep{ + Config: testAccAWSCloudFormationConfig_withParams_modified, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with_params", &stack), + ), + }, + }, + }) +} + func testAccCheckCloudFormationStackExists(n string, stack *cloudformation.Stack) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -225,3 +250,43 @@ resource "aws_sns_topic" "cf-updates" { name = "tf-cf-notifications" } ` + +var tpl_testAccAWSCloudFormationConfig_withParams = ` +resource "aws_cloudformation_stack" "with_params" { + name = "tf-stack-with-params" + parameters { + VpcCIDR = "%s" + } + template_body = <