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