From 72d3d7ed9b83985959298e26751007b67b0d5787 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 7 Jan 2016 11:44:49 +0000 Subject: [PATCH] provider/aws: Fix template_url/template_body conflict --- .../aws/resource_aws_cloudformation_stack.go | 6 +- .../resource_aws_cloudformation_stack_test.go | 81 +++++++++++++++++++ .../cloudformation-template.json | 19 +++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 builtin/providers/aws/test-fixtures/cloudformation-template.json diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack.go b/builtin/providers/aws/resource_aws_cloudformation_stack.go index d59b39329..ded8ee25a 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 192995685..f4d21dae8 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 = <