diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack.go b/builtin/providers/aws/resource_aws_cloudformation_stack.go index d59b393292e9..ded8ee25a570 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack.go @@ -269,12 +269,12 @@ func resourceAwsCloudFormationStackUpdate(d *schema.ResourceData, meta interface } // 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 v, ok := d.GetOk("template_url"); ok { input.TemplateURL = aws.String(v.(string)) } + if v, ok := d.GetOk("template_body"); ok && input.TemplateURL == nil { + input.TemplateBody = aws.String(normalizeJson(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 192995685bdb..f4d21dae8713 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go @@ -2,7 +2,9 @@ package aws import ( "fmt" + "math/rand" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" @@ -89,6 +91,31 @@ func TestAccAWSCloudFormation_withParams(t *testing.T) { }) } +// Regression for https://github.com/hashicorp/terraform/issues/4534 +func TestAccAWSCloudFormation_withUrl_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_templateUrl_withParams, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack), + ), + }, + resource.TestStep{ + Config: testAccAWSCloudFormationConfig_templateUrl_withParams_modified, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudFormationStackExists("aws_cloudformation_stack.with-url-and-params", &stack), + ), + }, + }, + }) +} + func testAccCheckCloudFormationStackExists(n string, stack *cloudformation.Stack) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -293,3 +320,57 @@ var testAccAWSCloudFormationConfig_withParams = fmt.Sprintf( var testAccAWSCloudFormationConfig_withParams_modified = fmt.Sprintf( tpl_testAccAWSCloudFormationConfig_withParams, "12.0.0.0/16") + +var tpl_testAccAWSCloudFormationConfig_templateUrl_withParams = ` +resource "aws_s3_bucket" "b" { + bucket = "%s" + acl = "public-read" + policy = <