diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack.go b/builtin/providers/aws/resource_aws_cloudformation_stack.go index 3486c6a5b..d59b39329 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack.go @@ -268,12 +268,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()) } diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go index 31b816d1a..192995685 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] @@ -228,3 +253,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 = <