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
|
||||
|
||||
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,9 +27,11 @@ func TestAccDataSourceAwsSubnetIDs(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
const testAccDataSourceAwsSubnetIDsConfigWithDataSource = `
|
||||
func testAccDataSourceAwsSubnetIDsConfigWithDataSource(rInt int) string {
|
||||
return fmt.Sprintf(
|
||||
`
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "172.16.0.0/16"
|
||||
cidr_block = "172.%d.0.0/16"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-subnet-ids-data-source"
|
||||
|
@ -35,7 +40,7 @@ resource "aws_vpc" "test" {
|
|||
|
||||
resource "aws_subnet" "test" {
|
||||
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"
|
||||
|
||||
tags {
|
||||
|
@ -46,10 +51,13 @@ resource "aws_subnet" "test" {
|
|||
data "aws_subnet_ids" "selected" {
|
||||
vpc_id = "${aws_vpc.test.id}"
|
||||
}
|
||||
`
|
||||
const testAccDataSourceAwsSubnetIDsConfig = `
|
||||
`, rInt, rInt)
|
||||
}
|
||||
|
||||
func testAccDataSourceAwsSubnetIDsConfig(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "172.16.0.0/16"
|
||||
cidr_block = "172.%d.0.0/16"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-subnet-ids-data-source"
|
||||
|
@ -58,11 +66,12 @@ resource "aws_vpc" "test" {
|
|||
|
||||
resource "aws_subnet" "test" {
|
||||
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"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-subnet-ids-data-source"
|
||||
}
|
||||
}
|
||||
`
|
||||
`, rInt, rInt)
|
||||
}
|
||||
|
|
|
@ -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,13 +78,14 @@ func testAccDataSourceAwsSubnetCheck(name string) resource.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
const testAccDataSourceAwsSubnetConfig = `
|
||||
func testAccDataSourceAwsSubnetConfig(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "172.16.0.0/16"
|
||||
cidr_block = "172.%d.0.0/16"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-subnet-data-source"
|
||||
|
@ -90,11 +94,11 @@ resource "aws_vpc" "test" {
|
|||
|
||||
resource "aws_subnet" "test" {
|
||||
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"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-subnet-data-source"
|
||||
Name = "terraform-testacc-subnet-data-source-%d"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,4 +126,5 @@ data "aws_subnet" "by_filter" {
|
|||
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) {
|
||||
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 = <<EOF
|
||||
{
|
||||
"Version": "2008-10-17",
|
||||
|
@ -933,7 +935,7 @@ EOF
|
|||
}
|
||||
|
||||
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}"
|
||||
policy = <<EOF
|
||||
{
|
||||
|
@ -957,16 +959,22 @@ EOF
|
|||
}
|
||||
|
||||
resource "aws_alb_target_group" "test" {
|
||||
name = "tf-acc-test-ecs-ghost"
|
||||
name = "tf-acc-test-ecs-ghost-%s"
|
||||
port = 80
|
||||
protocol = "HTTP"
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
tags {
|
||||
Name = "TestAccAWSEcsService_withAlb"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_alb" "main" {
|
||||
name = "tf-acc-test-test-alb-ecs"
|
||||
name = "tf-acc-test-alb-ecs-%s"
|
||||
internal = true
|
||||
subnets = ["${aws_subnet.main.*.id}"]
|
||||
tags {
|
||||
Name = "TestAccAWSEcsService_withAlb"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_alb_listener" "front_end" {
|
||||
|
@ -981,7 +989,7 @@ resource "aws_alb_listener" "front_end" {
|
|||
}
|
||||
|
||||
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}"
|
||||
task_definition = "${aws_ecs_task_definition.with_lb_changes.arn}"
|
||||
desired_count = 1
|
||||
|
@ -998,4 +1006,5 @@ resource "aws_ecs_service" "with_alb" {
|
|||
"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" {
|
||||
depends_on = ["aws_iam_role_policy.firehose"]
|
||||
name = "terraform-kinesis-firehose-basictest-cloudwatch"
|
||||
name = "terraform-kinesis-firehose-cloudwatch-%d"
|
||||
destination = "s3"
|
||||
s3_configuration {
|
||||
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 + `
|
||||
|
|
Loading…
Reference in New Issue