diff --git a/builtin/providers/aws/data_source_aws_subnet_ids_test.go b/builtin/providers/aws/data_source_aws_subnet_ids_test.go index 53c26aa37..35de8379d 100644 --- a/builtin/providers/aws/data_source_aws_subnet_ids_test.go +++ b/builtin/providers/aws/data_source_aws_subnet_ids_test.go @@ -1,21 +1,24 @@ package aws import ( + "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccDataSourceAwsSubnetIDs(t *testing.T) { + rInt := acctest.RandIntRange(0, 256) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAwsSubnetIDsConfig, + Config: testAccDataSourceAwsSubnetIDsConfig(rInt), }, { - Config: testAccDataSourceAwsSubnetIDsConfigWithDataSource, + Config: testAccDataSourceAwsSubnetIDsConfigWithDataSource(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.aws_subnet_ids.selected", "ids.#", "1"), ), @@ -24,45 +27,51 @@ func TestAccDataSourceAwsSubnetIDs(t *testing.T) { }) } -const testAccDataSourceAwsSubnetIDsConfigWithDataSource = ` -resource "aws_vpc" "test" { - cidr_block = "172.16.0.0/16" +func testAccDataSourceAwsSubnetIDsConfigWithDataSource(rInt int) string { + return fmt.Sprintf( + ` + resource "aws_vpc" "test" { + cidr_block = "172.%d.0.0/16" - tags { - Name = "terraform-testacc-subnet-ids-data-source" - } + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } + } + + resource "aws_subnet" "test" { + vpc_id = "${aws_vpc.test.id}" + cidr_block = "172.%d.123.0/24" + availability_zone = "us-west-2a" + + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } + } + + data "aws_subnet_ids" "selected" { + vpc_id = "${aws_vpc.test.id}" + } + `, rInt, rInt) } -resource "aws_subnet" "test" { - vpc_id = "${aws_vpc.test.id}" - cidr_block = "172.16.123.0/24" - availability_zone = "us-west-2a" +func testAccDataSourceAwsSubnetIDsConfig(rInt int) string { + return fmt.Sprintf(` + resource "aws_vpc" "test" { + cidr_block = "172.%d.0.0/16" - tags { - Name = "terraform-testacc-subnet-ids-data-source" - } + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } + } + + resource "aws_subnet" "test" { + vpc_id = "${aws_vpc.test.id}" + cidr_block = "172.%d.123.0/24" + availability_zone = "us-west-2a" + + tags { + Name = "terraform-testacc-subnet-ids-data-source" + } + } + `, rInt, rInt) } - -data "aws_subnet_ids" "selected" { - vpc_id = "${aws_vpc.test.id}" -} -` -const testAccDataSourceAwsSubnetIDsConfig = ` -resource "aws_vpc" "test" { - cidr_block = "172.16.0.0/16" - - tags { - Name = "terraform-testacc-subnet-ids-data-source" - } -} - -resource "aws_subnet" "test" { - vpc_id = "${aws_vpc.test.id}" - cidr_block = "172.16.123.0/24" - availability_zone = "us-west-2a" - - tags { - Name = "terraform-testacc-subnet-ids-data-source" - } -} -` diff --git a/builtin/providers/aws/data_source_aws_subnet_test.go b/builtin/providers/aws/data_source_aws_subnet_test.go index 51a764657..73a900751 100644 --- a/builtin/providers/aws/data_source_aws_subnet_test.go +++ b/builtin/providers/aws/data_source_aws_subnet_test.go @@ -4,30 +4,33 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccDataSourceAwsSubnet(t *testing.T) { + rInt := acctest.RandIntRange(0, 256) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccDataSourceAwsSubnetConfig, + Config: testAccDataSourceAwsSubnetConfig(rInt), Check: resource.ComposeTestCheckFunc( - testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_id"), - testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_cidr"), - testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_tag"), - testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_vpc"), - testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_filter"), + testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_id", rInt), + testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_cidr", rInt), + testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_tag", rInt), + testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_vpc", rInt), + testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_filter", rInt), ), }, }, }) } -func testAccDataSourceAwsSubnetCheck(name string) resource.TestCheckFunc { +func testAccDataSourceAwsSubnetCheck(name string, rInt int) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -61,13 +64,13 @@ func testAccDataSourceAwsSubnetCheck(name string) resource.TestCheckFunc { ) } - if attr["cidr_block"] != "172.16.123.0/24" { + if attr["cidr_block"] != fmt.Sprintf("172.%d.123.0/24", rInt) { return fmt.Errorf("bad cidr_block %s", attr["cidr_block"]) } if attr["availability_zone"] != "us-west-2a" { return fmt.Errorf("bad availability_zone %s", attr["availability_zone"]) } - if attr["tags.Name"] != "terraform-testacc-subnet-data-source" { + if attr["tags.Name"] != fmt.Sprintf("terraform-testacc-subnet-data-source-%d", rInt) { return fmt.Errorf("bad Name tag %s", attr["tags.Name"]) } @@ -75,51 +78,53 @@ func testAccDataSourceAwsSubnetCheck(name string) resource.TestCheckFunc { } } -const testAccDataSourceAwsSubnetConfig = ` -provider "aws" { - region = "us-west-2" +func testAccDataSourceAwsSubnetConfig(rInt int) string { + return fmt.Sprintf(` + provider "aws" { + region = "us-west-2" + } + + resource "aws_vpc" "test" { + cidr_block = "172.%d.0.0/16" + + tags { + Name = "terraform-testacc-subnet-data-source" + } + } + + resource "aws_subnet" "test" { + vpc_id = "${aws_vpc.test.id}" + cidr_block = "172.%d.123.0/24" + availability_zone = "us-west-2a" + + tags { + Name = "terraform-testacc-subnet-data-source-%d" + } + } + + data "aws_subnet" "by_id" { + id = "${aws_subnet.test.id}" + } + + data "aws_subnet" "by_cidr" { + cidr_block = "${aws_subnet.test.cidr_block}" + } + + data "aws_subnet" "by_tag" { + tags { + Name = "${aws_subnet.test.tags["Name"]}" + } + } + + data "aws_subnet" "by_vpc" { + vpc_id = "${aws_subnet.test.vpc_id}" + } + + data "aws_subnet" "by_filter" { + filter { + name = "vpc-id" + values = ["${aws_subnet.test.vpc_id}"] + } + } + `, rInt, rInt, rInt) } - -resource "aws_vpc" "test" { - cidr_block = "172.16.0.0/16" - - tags { - Name = "terraform-testacc-subnet-data-source" - } -} - -resource "aws_subnet" "test" { - vpc_id = "${aws_vpc.test.id}" - cidr_block = "172.16.123.0/24" - availability_zone = "us-west-2a" - - tags { - Name = "terraform-testacc-subnet-data-source" - } -} - -data "aws_subnet" "by_id" { - id = "${aws_subnet.test.id}" -} - -data "aws_subnet" "by_cidr" { - cidr_block = "${aws_subnet.test.cidr_block}" -} - -data "aws_subnet" "by_tag" { - tags { - Name = "${aws_subnet.test.tags["Name"]}" - } -} - -data "aws_subnet" "by_vpc" { - vpc_id = "${aws_subnet.test.vpc_id}" -} - -data "aws_subnet" "by_filter" { - filter { - name = "vpc-id" - values = ["${aws_subnet.test.vpc_id}"] - } -} -` diff --git a/builtin/providers/aws/resource_aws_ecs_service_test.go b/builtin/providers/aws/resource_aws_ecs_service_test.go index 8be48aa95..6440393ba 100644 --- a/builtin/providers/aws/resource_aws_ecs_service_test.go +++ b/builtin/providers/aws/resource_aws_ecs_service_test.go @@ -243,13 +243,14 @@ func TestAccAWSEcsService_withEcsClusterName(t *testing.T) { } func TestAccAWSEcsService_withAlb(t *testing.T) { + rString := acctest.RandString(10) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEcsServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEcsServiceWithAlb, + Config: testAccAWSEcsServiceWithAlb(rString), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.with_alb"), ), @@ -874,7 +875,8 @@ resource "aws_ecs_service" "jenkins" { } ` -var testAccAWSEcsServiceWithAlb = ` +func testAccAWSEcsServiceWithAlb(rString string) string { + return fmt.Sprintf(` data "aws_availability_zones" "available" {} resource "aws_vpc" "main" { @@ -889,7 +891,7 @@ resource "aws_subnet" "main" { } resource "aws_ecs_cluster" "main" { - name = "terraform_acc_test_ecs_15" + name = "terraform_acc_test_ecs_%s" } resource "aws_ecs_task_definition" "with_lb_changes" { @@ -914,7 +916,7 @@ DEFINITION } resource "aws_iam_role" "ecs_service" { - name = "tf_acc_test_15_role" + name = "tf_acc_test_%s_role" assume_role_policy = <