Merge pull request #4540 from TimeIncOSS/b-aws-cf-url-fix

provider/aws: Fix template_url/template_body conflict
This commit is contained in:
Radek Simko 2016-01-07 21:10:43 +00:00
commit b65f9db48e
3 changed files with 103 additions and 3 deletions

View File

@ -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())

View File

@ -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 = <<POLICY
{
"Version":"2008-10-17",
"Statement": [
{
"Sid":"AllowPublicRead",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::%s/*"
}
]
}
POLICY
website {
index_document = "index.html"
error_document = "error.html"
}
}
resource "aws_s3_bucket_object" "object" {
bucket = "${aws_s3_bucket.b.id}"
key = "tf-cf-stack.json"
source = "test-fixtures/cloudformation-template.json"
}
resource "aws_cloudformation_stack" "with-url-and-params" {
name = "tf-stack-template-url-with-params"
parameters {
VpcCIDR = "%s"
}
template_url = "https://${aws_s3_bucket.b.id}.s3-us-west-2.amazonaws.com/${aws_s3_bucket_object.object.key}"
on_failure = "DELETE"
timeout_in_minutes = 1
}
`
var cfRandInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
var cfBucketName = "tf-stack-with-url-and-params-" + fmt.Sprintf("%d", cfRandInt)
var testAccAWSCloudFormationConfig_templateUrl_withParams = fmt.Sprintf(
tpl_testAccAWSCloudFormationConfig_templateUrl_withParams,
cfBucketName, cfBucketName, "11.0.0.0/16")
var testAccAWSCloudFormationConfig_templateUrl_withParams_modified = fmt.Sprintf(
tpl_testAccAWSCloudFormationConfig_templateUrl_withParams,
cfBucketName, cfBucketName, "13.0.0.0/16")

View File

@ -0,0 +1,19 @@
{
"Parameters" : {
"VpcCIDR" : {
"Description" : "CIDR to be used for the VPC",
"Type" : "String"
}
},
"Resources" : {
"MyVPC": {
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : {"Ref": "VpcCIDR"},
"Tags" : [
{"Key": "Name", "Value": "Primary_CF_VPC"}
]
}
}
}
}