diff --git a/builtin/providers/aws/import_aws_customer_gateway_test.go b/builtin/providers/aws/import_aws_customer_gateway_test.go index 0c066a33f0..96e791ce86 100644 --- a/builtin/providers/aws/import_aws_customer_gateway_test.go +++ b/builtin/providers/aws/import_aws_customer_gateway_test.go @@ -9,14 +9,16 @@ import ( func TestAccAWSCustomerGateway_importBasic(t *testing.T) { resourceName := "aws_customer_gateway.foo" - randInt := acctest.RandInt() + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCustomerGatewayConfig(randInt), + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), }, resource.TestStep{ diff --git a/builtin/providers/aws/import_aws_vpn_connection_test.go b/builtin/providers/aws/import_aws_vpn_connection_test.go index a9dd41b583..a7297a2207 100644 --- a/builtin/providers/aws/import_aws_vpn_connection_test.go +++ b/builtin/providers/aws/import_aws_vpn_connection_test.go @@ -3,11 +3,13 @@ package aws import ( "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccAWSVpnConnection_importBasic(t *testing.T) { resourceName := "aws_vpn_connection.foo" + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -15,7 +17,7 @@ func TestAccAWSVpnConnection_importBasic(t *testing.T) { CheckDestroy: testAccAwsVpnConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsVpnConnectionConfig, + Config: testAccAwsVpnConnectionConfig(rBgpAsn), }, { ResourceName: resourceName, diff --git a/builtin/providers/aws/resource_aws_customer_gateway_test.go b/builtin/providers/aws/resource_aws_customer_gateway_test.go index 118c2d71e2..9606a45571 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway_test.go +++ b/builtin/providers/aws/resource_aws_customer_gateway_test.go @@ -17,7 +17,8 @@ import ( func TestAccAWSCustomerGateway_basic(t *testing.T) { var gateway ec2.CustomerGateway - randInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_customer_gateway.foo", @@ -25,19 +26,19 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig(randInt), + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigUpdateTags(randInt), + Config: testAccCustomerGatewayConfigUpdateTags(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigForceReplace(randInt), + Config: testAccCustomerGatewayConfigForceReplace(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), @@ -48,7 +49,8 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) { func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { var gateway ec2.CustomerGateway - randInt := acctest.RandInt() + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_customer_gateway.foo", @@ -56,13 +58,13 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig(randInt), + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigIdentical(randInt), + Config: testAccCustomerGatewayConfigIdentical(rInt, rBgpAsn), ExpectError: regexp.MustCompile("An existing customer gateway"), }, }, @@ -70,15 +72,16 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { } func TestAccAWSCustomerGateway_disappears(t *testing.T) { + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) var gateway ec2.CustomerGateway - randInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig(randInt), + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccAWSCustomerGatewayDisappears(&gateway), @@ -194,67 +197,66 @@ func testAccCheckCustomerGateway(gatewayResource string, cgw *ec2.CustomerGatewa } } -func testAccCustomerGatewayConfig(randInt int) string { - return fmt.Sprintf(` - resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway-%d" - } - } - `, randInt) -} - -func testAccCustomerGatewayConfigIdentical(randInt int) string { +func testAccCustomerGatewayConfig(rInt, rBgpAsn int) string { return fmt.Sprintf(` resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 + bgp_asn = %d ip_address = "172.0.0.1" type = "ipsec.1" tags { Name = "foo-gateway-%d" } } + `, rBgpAsn, rInt) +} +func testAccCustomerGatewayConfigIdentical(randInt, rBgpAsn int) string { + return fmt.Sprintf(` + resource "aws_customer_gateway" "foo" { + bgp_asn = %d + ip_address = "172.0.0.1" + type = "ipsec.1" + tags { + Name = "foo-gateway-%d" + } + } resource "aws_customer_gateway" "identical" { - bgp_asn = 65000 + bgp_asn = %d ip_address = "172.0.0.1" type = "ipsec.1" tags { Name = "foo-gateway-identical-%d" } } - `, randInt, randInt) + `, rBgpAsn, randInt, rBgpAsn, randInt) } // Add the Another: "tag" tag. -func testAccCustomerGatewayConfigUpdateTags(randInt int) string { - return fmt.Sprintf(` - resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway-%d" - Another = "tag-%d" - } - } - `, randInt, randInt) -} - -// Change the ip_address. -func testAccCustomerGatewayConfigForceReplace(randInt int) string { +func testAccCustomerGatewayConfigUpdateTags(rInt, rBgpAsn int) string { return fmt.Sprintf(` resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.10.10.1" + bgp_asn = %d + ip_address = "172.0.0.1" type = "ipsec.1" tags { Name = "foo-gateway-%d" - Another = "tag-%d" + Another = "tag" } } - `, randInt, randInt) + `, rBgpAsn, rInt) +} + +// Change the ip_address. +func testAccCustomerGatewayConfigForceReplace(rInt, rBgpAsn int) string { + return fmt.Sprintf(` + resource "aws_customer_gateway" "foo" { + bgp_asn = %d + ip_address = "172.10.10.1" + type = "ipsec.1" + tags { + Name = "foo-gateway-%d" + Another = "tag" + } + } + `, rBgpAsn, rInt) } diff --git a/builtin/providers/aws/resource_aws_emr_cluster_test.go b/builtin/providers/aws/resource_aws_emr_cluster_test.go index a0bac7fcf6..2760e8e765 100644 --- a/builtin/providers/aws/resource_aws_emr_cluster_test.go +++ b/builtin/providers/aws/resource_aws_emr_cluster_test.go @@ -241,7 +241,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } resource "aws_security_group" "allow_all" { - name = "allow_all" + name = "allow_all_%d" description = "Allow all inbound traffic" vpc_id = "${aws_vpc.main.id}" @@ -275,7 +275,7 @@ resource "aws_vpc" "main" { enable_dns_hostnames = true tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -284,7 +284,7 @@ resource "aws_subnet" "main" { cidr_block = "168.31.0.0/20" tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -478,7 +478,7 @@ EOT # IAM Role for autoscaling resource "aws_iam_role" "emr-autoscaling-role" { - name = "EMR_AutoScaling_DefaultRole" + name = "EMR_AutoScaling_DefaultRole_%d" assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}" } @@ -486,7 +486,6 @@ data "aws_iam_policy_document" "emr-autoscaling-role-policy" { statement { effect = "Allow" actions = ["sts:AssumeRole"] - principals = { type = "Service" identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"] @@ -498,7 +497,7 @@ resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" { role = "${aws_iam_role.emr-autoscaling-role.name}" policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole" } -`, r, r, r, r, r, r) +`, r, r, r, r, r, r, r, r, r, r) } func testAccAWSEmrClusterConfigTerminationPolicyUpdated(r int) string { @@ -548,7 +547,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } resource "aws_security_group" "allow_all" { - name = "allow_all" + name = "allow_all_%d" description = "Allow all inbound traffic" vpc_id = "${aws_vpc.main.id}" @@ -582,7 +581,7 @@ resource "aws_vpc" "main" { enable_dns_hostnames = true tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -591,7 +590,7 @@ resource "aws_subnet" "main" { cidr_block = "168.31.0.0/20" tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -785,7 +784,7 @@ EOT # IAM Role for autoscaling resource "aws_iam_role" "emr-autoscaling-role" { - name = "EMR_AutoScaling_DefaultRole" + name = "EMR_AutoScaling_DefaultRole_%d" assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}" } @@ -793,7 +792,7 @@ data "aws_iam_policy_document" "emr-autoscaling-role-policy" { statement { effect = "Allow" actions = ["sts:AssumeRole"] - + principals = { type = "Service" identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"] @@ -805,7 +804,7 @@ resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" { role = "${aws_iam_role.emr-autoscaling-role.name}" policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole" } -`, r, r, r, r, r, r) +`, r, r, r, r, r, r, r, r, r, r) } func testAccAWSEmrClusterConfigVisibleToAllUsersUpdated(r int) string { @@ -855,7 +854,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } resource "aws_security_group" "allow_all" { - name = "allow_all" + name = "allow_all_%d" description = "Allow all inbound traffic" vpc_id = "${aws_vpc.main.id}" @@ -889,7 +888,7 @@ resource "aws_vpc" "main" { enable_dns_hostnames = true tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -898,7 +897,7 @@ resource "aws_subnet" "main" { cidr_block = "168.31.0.0/20" tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -1092,7 +1091,7 @@ EOT # IAM Role for autoscaling resource "aws_iam_role" "emr-autoscaling-role" { - name = "EMR_AutoScaling_DefaultRole" + name = "EMR_AutoScaling_DefaultRole_%d" assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}" } @@ -1100,7 +1099,7 @@ data "aws_iam_policy_document" "emr-autoscaling-role-policy" { statement { effect = "Allow" actions = ["sts:AssumeRole"] - + principals = { type = "Service" identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"] @@ -1112,7 +1111,7 @@ resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" { role = "${aws_iam_role.emr-autoscaling-role.name}" policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole" } -`, r, r, r, r, r, r) +`, r, r, r, r, r, r, r, r, r, r) } func testAccAWSEmrClusterConfigUpdatedTags(r int) string { @@ -1161,7 +1160,7 @@ resource "aws_emr_cluster" "tf-test-cluster" { } resource "aws_security_group" "allow_all" { - name = "allow_all" + name = "allow_all_%d" description = "Allow all inbound traffic" vpc_id = "${aws_vpc.main.id}" @@ -1195,7 +1194,7 @@ resource "aws_vpc" "main" { enable_dns_hostnames = true tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -1204,7 +1203,7 @@ resource "aws_subnet" "main" { cidr_block = "168.31.0.0/20" tags { - name = "emr_test" + name = "emr_test_%d" } } @@ -1398,7 +1397,7 @@ EOT # IAM Role for autoscaling resource "aws_iam_role" "emr-autoscaling-role" { - name = "EMR_AutoScaling_DefaultRole" + name = "EMR_AutoScaling_DefaultRole_%d" assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}" } @@ -1406,7 +1405,7 @@ data "aws_iam_policy_document" "emr-autoscaling-role-policy" { statement { effect = "Allow" actions = ["sts:AssumeRole"] - + principals = { type = "Service" identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"] @@ -1418,5 +1417,5 @@ resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" { role = "${aws_iam_role.emr-autoscaling-role.name}" policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole" } -`, r, r, r, r, r, r) +`, r, r, r, r, r, r, r, r, r, r) } diff --git a/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go b/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go index 58738f4bdc..6ae57b1d52 100644 --- a/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go @@ -43,6 +43,7 @@ func TestAccAWSPolicyAttachment_basic(t *testing.T) { func TestAccAWSPolicyAttachment_paginatedEntities(t *testing.T) { var out iam.ListEntitiesForPolicyOutput + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -50,7 +51,7 @@ func TestAccAWSPolicyAttachment_paginatedEntities(t *testing.T) { CheckDestroy: testAccCheckAWSPolicyAttachmentDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSPolicyPaginatedAttachConfig, + Config: testAccAWSPolicyPaginatedAttachConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSPolicyAttachmentExists("aws_iam_policy_attachment.test-paginated-attach", 101, &out), ), @@ -302,34 +303,33 @@ resource "aws_iam_policy_attachment" "test-attach" { }`, u1, u2, u3) } -const testAccAWSPolicyPaginatedAttachConfig = ` +func testAccAWSPolicyPaginatedAttachConfig(rInt int) string { + return fmt.Sprintf(` resource "aws_iam_user" "user" { - count = 101 - name = "${format("paged-test-user-%d", count.index + 1)}" + count = 101 + name = "${format("paged-test-user-%d-%%d", count.index + 1)}" } - resource "aws_iam_policy" "policy" { - name = "test-policy" - description = "A test policy" - policy = <