Merge pull request #13551 from hashicorp/p-randomize-aws-tests
Randomize aws tests
This commit is contained in:
commit
d47a60f7c9
|
@ -1,21 +1,24 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDataSourceAwsSubnetIDs(t *testing.T) {
|
func TestAccDataSourceAwsSubnetIDs(t *testing.T) {
|
||||||
|
rInt := acctest.RandIntRange(0, 256)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccDataSourceAwsSubnetIDsConfig,
|
Config: testAccDataSourceAwsSubnetIDsConfig(rInt),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Config: testAccDataSourceAwsSubnetIDsConfigWithDataSource,
|
Config: testAccDataSourceAwsSubnetIDsConfigWithDataSource(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr("data.aws_subnet_ids.selected", "ids.#", "1"),
|
resource.TestCheckResourceAttr("data.aws_subnet_ids.selected", "ids.#", "1"),
|
||||||
),
|
),
|
||||||
|
@ -24,45 +27,51 @@ func TestAccDataSourceAwsSubnetIDs(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccDataSourceAwsSubnetIDsConfigWithDataSource = `
|
func testAccDataSourceAwsSubnetIDsConfigWithDataSource(rInt int) string {
|
||||||
resource "aws_vpc" "test" {
|
return fmt.Sprintf(
|
||||||
cidr_block = "172.16.0.0/16"
|
`
|
||||||
|
resource "aws_vpc" "test" {
|
||||||
|
cidr_block = "172.%d.0.0/16"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-ids-data-source"
|
Name = "terraform-testacc-subnet-ids-data-source"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "test" {
|
resource "aws_subnet" "test" {
|
||||||
vpc_id = "${aws_vpc.test.id}"
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
cidr_block = "172.16.123.0/24"
|
cidr_block = "172.%d.123.0/24"
|
||||||
availability_zone = "us-west-2a"
|
availability_zone = "us-west-2a"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-ids-data-source"
|
Name = "terraform-testacc-subnet-ids-data-source"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data "aws_subnet_ids" "selected" {
|
||||||
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
|
}
|
||||||
|
`, rInt, rInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet_ids" "selected" {
|
func testAccDataSourceAwsSubnetIDsConfig(rInt int) string {
|
||||||
vpc_id = "${aws_vpc.test.id}"
|
return fmt.Sprintf(`
|
||||||
}
|
resource "aws_vpc" "test" {
|
||||||
`
|
cidr_block = "172.%d.0.0/16"
|
||||||
const testAccDataSourceAwsSubnetIDsConfig = `
|
|
||||||
resource "aws_vpc" "test" {
|
|
||||||
cidr_block = "172.16.0.0/16"
|
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-ids-data-source"
|
Name = "terraform-testacc-subnet-ids-data-source"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "test" {
|
resource "aws_subnet" "test" {
|
||||||
vpc_id = "${aws_vpc.test.id}"
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
cidr_block = "172.16.123.0/24"
|
cidr_block = "172.%d.123.0/24"
|
||||||
availability_zone = "us-west-2a"
|
availability_zone = "us-west-2a"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-ids-data-source"
|
Name = "terraform-testacc-subnet-ids-data-source"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
`, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
|
@ -4,30 +4,33 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDataSourceAwsSubnet(t *testing.T) {
|
func TestAccDataSourceAwsSubnet(t *testing.T) {
|
||||||
|
rInt := acctest.RandIntRange(0, 256)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccDataSourceAwsSubnetConfig,
|
Config: testAccDataSourceAwsSubnetConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_id"),
|
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_id", rInt),
|
||||||
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_cidr"),
|
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_cidr", rInt),
|
||||||
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_tag"),
|
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_tag", rInt),
|
||||||
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_vpc"),
|
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_vpc", rInt),
|
||||||
testAccDataSourceAwsSubnetCheck("data.aws_subnet.by_filter"),
|
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 {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[name]
|
rs, ok := s.RootModule().Resources[name]
|
||||||
if !ok {
|
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"])
|
return fmt.Errorf("bad cidr_block %s", attr["cidr_block"])
|
||||||
}
|
}
|
||||||
if attr["availability_zone"] != "us-west-2a" {
|
if attr["availability_zone"] != "us-west-2a" {
|
||||||
return fmt.Errorf("bad availability_zone %s", attr["availability_zone"])
|
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"])
|
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,51 +78,53 @@ func testAccDataSourceAwsSubnetCheck(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccDataSourceAwsSubnetConfig = `
|
func testAccDataSourceAwsSubnetConfig(rInt int) string {
|
||||||
provider "aws" {
|
return fmt.Sprintf(`
|
||||||
|
provider "aws" {
|
||||||
region = "us-west-2"
|
region = "us-west-2"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_vpc" "test" {
|
resource "aws_vpc" "test" {
|
||||||
cidr_block = "172.16.0.0/16"
|
cidr_block = "172.%d.0.0/16"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-data-source"
|
Name = "terraform-testacc-subnet-data-source"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "test" {
|
resource "aws_subnet" "test" {
|
||||||
vpc_id = "${aws_vpc.test.id}"
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
cidr_block = "172.16.123.0/24"
|
cidr_block = "172.%d.123.0/24"
|
||||||
availability_zone = "us-west-2a"
|
availability_zone = "us-west-2a"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-subnet-data-source"
|
Name = "terraform-testacc-subnet-data-source-%d"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
data "aws_subnet" "by_id" {
|
data "aws_subnet" "by_id" {
|
||||||
id = "${aws_subnet.test.id}"
|
id = "${aws_subnet.test.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "by_cidr" {
|
data "aws_subnet" "by_cidr" {
|
||||||
cidr_block = "${aws_subnet.test.cidr_block}"
|
cidr_block = "${aws_subnet.test.cidr_block}"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "by_tag" {
|
data "aws_subnet" "by_tag" {
|
||||||
tags {
|
tags {
|
||||||
Name = "${aws_subnet.test.tags["Name"]}"
|
Name = "${aws_subnet.test.tags["Name"]}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "by_vpc" {
|
data "aws_subnet" "by_vpc" {
|
||||||
vpc_id = "${aws_subnet.test.vpc_id}"
|
vpc_id = "${aws_subnet.test.vpc_id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "by_filter" {
|
data "aws_subnet" "by_filter" {
|
||||||
filter {
|
filter {
|
||||||
name = "vpc-id"
|
name = "vpc-id"
|
||||||
values = ["${aws_subnet.test.vpc_id}"]
|
values = ["${aws_subnet.test.vpc_id}"]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
`, rInt, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
|
@ -243,13 +243,14 @@ func TestAccAWSEcsService_withEcsClusterName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSEcsService_withAlb(t *testing.T) {
|
func TestAccAWSEcsService_withAlb(t *testing.T) {
|
||||||
|
rString := acctest.RandString(10)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
|
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccAWSEcsServiceWithAlb,
|
Config: testAccAWSEcsServiceWithAlb(rString),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSEcsServiceExists("aws_ecs_service.with_alb"),
|
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" {}
|
data "aws_availability_zones" "available" {}
|
||||||
|
|
||||||
resource "aws_vpc" "main" {
|
resource "aws_vpc" "main" {
|
||||||
|
@ -889,7 +891,7 @@ resource "aws_subnet" "main" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_ecs_cluster" "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" {
|
resource "aws_ecs_task_definition" "with_lb_changes" {
|
||||||
|
@ -914,7 +916,7 @@ DEFINITION
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role" "ecs_service" {
|
resource "aws_iam_role" "ecs_service" {
|
||||||
name = "tf_acc_test_15_role"
|
name = "tf_acc_test_%s_role"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2008-10-17",
|
"Version": "2008-10-17",
|
||||||
|
@ -933,7 +935,7 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "ecs_service" {
|
resource "aws_iam_role_policy" "ecs_service" {
|
||||||
name = "tf_acc_test_15_policy"
|
name = "tf_acc_test_%s_policy"
|
||||||
role = "${aws_iam_role.ecs_service.name}"
|
role = "${aws_iam_role.ecs_service.name}"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
|
@ -957,16 +959,22 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_alb_target_group" "test" {
|
resource "aws_alb_target_group" "test" {
|
||||||
name = "tf-acc-test-ecs-ghost"
|
name = "tf-acc-test-ecs-ghost-%s"
|
||||||
port = 80
|
port = 80
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
vpc_id = "${aws_vpc.main.id}"
|
vpc_id = "${aws_vpc.main.id}"
|
||||||
|
tags {
|
||||||
|
Name = "TestAccAWSEcsService_withAlb"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_alb" "main" {
|
resource "aws_alb" "main" {
|
||||||
name = "tf-acc-test-test-alb-ecs"
|
name = "tf-acc-test-alb-ecs-%s"
|
||||||
internal = true
|
internal = true
|
||||||
subnets = ["${aws_subnet.main.*.id}"]
|
subnets = ["${aws_subnet.main.*.id}"]
|
||||||
|
tags {
|
||||||
|
Name = "TestAccAWSEcsService_withAlb"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_alb_listener" "front_end" {
|
resource "aws_alb_listener" "front_end" {
|
||||||
|
@ -981,7 +989,7 @@ resource "aws_alb_listener" "front_end" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_ecs_service" "with_alb" {
|
resource "aws_ecs_service" "with_alb" {
|
||||||
name = "tf-acc-test-ecs-ghost"
|
name = "tf-acc-test-ecs-ghost-%s"
|
||||||
cluster = "${aws_ecs_cluster.main.id}"
|
cluster = "${aws_ecs_cluster.main.id}"
|
||||||
task_definition = "${aws_ecs_task_definition.with_lb_changes.arn}"
|
task_definition = "${aws_ecs_task_definition.with_lb_changes.arn}"
|
||||||
desired_count = 1
|
desired_count = 1
|
||||||
|
@ -998,4 +1006,5 @@ resource "aws_ecs_service" "with_alb" {
|
||||||
"aws_alb_listener.front_end"
|
"aws_alb_listener.front_end"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
`
|
`, rString, rString, rString, rString, rString, rString)
|
||||||
|
}
|
||||||
|
|
|
@ -439,7 +439,7 @@ resource "aws_cloudwatch_log_stream" "test" {
|
||||||
|
|
||||||
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
|
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
|
||||||
depends_on = ["aws_iam_role_policy.firehose"]
|
depends_on = ["aws_iam_role_policy.firehose"]
|
||||||
name = "terraform-kinesis-firehose-basictest-cloudwatch"
|
name = "terraform-kinesis-firehose-cloudwatch-%d"
|
||||||
destination = "s3"
|
destination = "s3"
|
||||||
s3_configuration {
|
s3_configuration {
|
||||||
role_arn = "${aws_iam_role.firehose.arn}"
|
role_arn = "${aws_iam_role.firehose.arn}"
|
||||||
|
@ -451,7 +451,7 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, rInt, accountId, rInt, rInt, rInt, rInt)
|
`, rInt, accountId, rInt, rInt, rInt, rInt, rInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccKinesisFirehoseDeliveryStreamConfig_s3basic = testAccKinesisFirehoseDeliveryStreamBaseConfig + `
|
var testAccKinesisFirehoseDeliveryStreamConfig_s3basic = testAccKinesisFirehoseDeliveryStreamBaseConfig + `
|
||||||
|
|
Loading…
Reference in New Issue