From c06c17c914fc29d8e6b2b6e6fe20c7f0a0a063f2 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 28 Mar 2017 16:08:08 -0600 Subject: [PATCH 1/7] Adds randomness to emr cluster tests --- .../aws/resource_aws_emr_cluster_test.go | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) 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) } From 0aa9d71f7fb27ed7172e0f5626924d09856db588 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 29 Mar 2017 14:24:19 -0600 Subject: [PATCH 2/7] add randomness to iam policy attachments --- .../aws/resource_aws_iam_policy_attachment_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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..97da2b9097 100644 --- a/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go @@ -6,6 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" + randomprovider "github.com/hashicorp/terraform/builtin/providers/random" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -45,8 +46,11 @@ func TestAccAWSPolicyAttachment_paginatedEntities(t *testing.T) { var out iam.ListEntitiesForPolicyOutput resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: map[string]terraform.ResourceProvider{ + "aws": testAccProvider, + "random": randomprovider.Provider(), + }, CheckDestroy: testAccCheckAWSPolicyAttachmentDestroy, Steps: []resource.TestStep{ resource.TestStep{ @@ -303,9 +307,13 @@ resource "aws_iam_policy_attachment" "test-attach" { } const testAccAWSPolicyPaginatedAttachConfig = ` +resource "random_id" "user_id" { + byte_length = 10 +} + resource "aws_iam_user" "user" { count = 101 - name = "${format("paged-test-user-%d", count.index + 1)}" + name = "${format("paged-test-user-${random_id.user_id.hex}-%d", count.index + 1)}" } resource "aws_iam_policy" "policy" { From fae435c5d860076cc08442a416d50ac3ef4182eb Mon Sep 17 00:00:00 2001 From: = Date: Wed, 29 Mar 2017 15:10:21 -0600 Subject: [PATCH 3/7] Add randomness to vpn connection test --- .../aws/resource_aws_vpn_connection_test.go | 83 +++++++++++-------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpn_connection_test.go b/builtin/providers/aws/resource_aws_vpn_connection_test.go index a07bdd10ba..709e84c872 100644 --- a/builtin/providers/aws/resource_aws_vpn_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpn_connection_test.go @@ -8,11 +8,13 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSVpnConnection_basic(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_vpn_connection.foo", @@ -31,7 +33,7 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { ), }, { - Config: testAccAwsVpnConnectionConfigUpdate, + Config: testAccAwsVpnConnectionConfigUpdate(rInt), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", @@ -46,6 +48,7 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { } func TestAccAWSVpnConnection_withoutStaticRoutes(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_vpn_connection.foo", @@ -53,7 +56,7 @@ func TestAccAWSVpnConnection_withoutStaticRoutes(t *testing.T) { CheckDestroy: testAccAwsVpnConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsVpnConnectionConfigUpdate, + Config: testAccAwsVpnConnectionConfigUpdate(rInt), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", @@ -161,47 +164,55 @@ func TestAWSVpnConnection_xmlconfig(t *testing.T) { } const testAccAwsVpnConnectionConfig = ` -resource "aws_vpn_gateway" "vpn_gateway" { - tags { - Name = "vpn_gateway" - } -} + resource "aws_vpn_gateway" "vpn_gateway" { + tags { + Name = "vpn_gateway" + } + } -resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 - ip_address = "178.0.0.1" - type = "ipsec.1" -} + resource "aws_customer_gateway" "customer_gateway" { + bgp_asn = 65000 + ip_address = "178.0.0.1" + type = "ipsec.1" + tags { + Name = "main-customer-gateway" + } + } -resource "aws_vpn_connection" "foo" { - vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" - customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" - type = "ipsec.1" - static_routes_only = true -} -` + resource "aws_vpn_connection" "foo" { + vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" + customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" + type = "ipsec.1" + static_routes_only = true + } + ` // Change static_routes_only to be false, forcing a refresh. -const testAccAwsVpnConnectionConfigUpdate = ` -resource "aws_vpn_gateway" "vpn_gateway" { - tags { - Name = "vpn_gateway" - } -} +func testAccAwsVpnConnectionConfigUpdate(rInt int) string { + return fmt.Sprintf(` + resource "aws_vpn_gateway" "vpn_gateway" { + tags { + Name = "vpn_gateway" + } + } -resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 - ip_address = "178.0.0.1" - type = "ipsec.1" -} + resource "aws_customer_gateway" "customer_gateway" { + bgp_asn = 65000 + ip_address = "178.0.0.1" + type = "ipsec.1" + tags { + Name = "main-customer-gateway-%d" + } + } -resource "aws_vpn_connection" "foo" { - vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" - customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" - type = "ipsec.1" - static_routes_only = false + resource "aws_vpn_connection" "foo" { + vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" + customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" + type = "ipsec.1" + static_routes_only = false + } + `, rInt) } -` // Test our VPN tunnel config XML parsing const testAccAwsVpnTunnelInfoXML = ` From e2d7d5fc68e1c7940ef732d6abc798e6ba2797c7 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 3 Apr 2017 08:11:54 -0600 Subject: [PATCH 4/7] Removed random provider frm iam policy attachment test --- ...resource_aws_iam_policy_attachment_test.go | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) 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 97da2b9097..e2e9c2a8ed 100644 --- a/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go @@ -6,7 +6,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" - randomprovider "github.com/hashicorp/terraform/builtin/providers/random" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -44,17 +43,15 @@ 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) }, - Providers: map[string]terraform.ResourceProvider{ - "aws": testAccProvider, - "random": randomprovider.Provider(), - }, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, 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), ), @@ -306,38 +303,33 @@ resource "aws_iam_policy_attachment" "test-attach" { }`, u1, u2, u3) } -const testAccAWSPolicyPaginatedAttachConfig = ` -resource "random_id" "user_id" { - byte_length = 10 -} - +func testAccAWSPolicyPaginatedAttachConfig(rInt int) string { + return fmt.Sprintf(` resource "aws_iam_user" "user" { - count = 101 - name = "${format("paged-test-user-${random_id.user_id.hex}-%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 = < Date: Mon, 3 Apr 2017 11:17:59 -0600 Subject: [PATCH 5/7] randomizes all bgp_asn values --- .../aws/import_aws_customer_gateway_test.go | 5 +- .../aws/import_aws_vpn_connection_test.go | 4 +- .../aws/resource_aws_customer_gateway_test.go | 118 ++++++++++-------- .../aws/resource_aws_vpn_connection_test.go | 58 +++++---- .../aws/resource_vpn_connection_route_test.go | 90 ++++++------- 5 files changed, 152 insertions(+), 123 deletions(-) diff --git a/builtin/providers/aws/import_aws_customer_gateway_test.go b/builtin/providers/aws/import_aws_customer_gateway_test.go index 37662760db..96e791ce86 100644 --- a/builtin/providers/aws/import_aws_customer_gateway_test.go +++ b/builtin/providers/aws/import_aws_customer_gateway_test.go @@ -3,11 +3,14 @@ package aws import ( "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) func TestAccAWSCustomerGateway_importBasic(t *testing.T) { resourceName := "aws_customer_gateway.foo" + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -15,7 +18,7 @@ func TestAccAWSCustomerGateway_importBasic(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCustomerGatewayConfig, + 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 1938ce0bdd..9606a45571 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway_test.go +++ b/builtin/providers/aws/resource_aws_customer_gateway_test.go @@ -10,12 +10,15 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSCustomerGateway_basic(t *testing.T) { var gateway ec2.CustomerGateway + rBgpAsn := acctest.RandIntRange(64512, 65534) + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_customer_gateway.foo", @@ -23,19 +26,19 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig, + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigUpdateTags, + Config: testAccCustomerGatewayConfigUpdateTags(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigForceReplace, + Config: testAccCustomerGatewayConfigForceReplace(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), @@ -46,6 +49,8 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) { func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { var gateway ec2.CustomerGateway + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_customer_gateway.foo", @@ -53,13 +58,13 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig, + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), ), }, { - Config: testAccCustomerGatewayConfigIdentical, + Config: testAccCustomerGatewayConfigIdentical(rInt, rBgpAsn), ExpectError: regexp.MustCompile("An existing customer gateway"), }, }, @@ -67,6 +72,8 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { } func TestAccAWSCustomerGateway_disappears(t *testing.T) { + rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) var gateway ec2.CustomerGateway resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -74,7 +81,7 @@ func TestAccAWSCustomerGateway_disappears(t *testing.T) { CheckDestroy: testAccCheckCustomerGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccCustomerGatewayConfig, + Config: testAccCustomerGatewayConfig(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccAWSCustomerGatewayDisappears(&gateway), @@ -190,59 +197,66 @@ func testAccCheckCustomerGateway(gatewayResource string, cgw *ec2.CustomerGatewa } } -const testAccCustomerGatewayConfig = ` -resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway" - } -} -` - -const testAccCustomerGatewayConfigIdentical = ` -resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway" - } +func testAccCustomerGatewayConfig(rInt, 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" + } + } + `, rBgpAsn, rInt) } -resource "aws_customer_gateway" "identical" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway-identical" - } +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 = %d + ip_address = "172.0.0.1" + type = "ipsec.1" + tags { + Name = "foo-gateway-identical-%d" + } + } + `, rBgpAsn, randInt, rBgpAsn, randInt) } -` // Add the Another: "tag" tag. -const testAccCustomerGatewayConfigUpdateTags = ` -resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.0.0.1" - type = "ipsec.1" - tags { - Name = "foo-gateway" - Another = "tag" +func testAccCustomerGatewayConfigUpdateTags(rInt, 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" + Another = "tag" + } } + `, rBgpAsn, rInt) } -` // Change the ip_address. -const testAccCustomerGatewayConfigForceReplace = ` -resource "aws_customer_gateway" "foo" { - bgp_asn = 65000 - ip_address = "172.10.10.1" - type = "ipsec.1" - tags { - Name = "foo-gateway" - Another = "tag" - } +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_vpn_connection_test.go b/builtin/providers/aws/resource_aws_vpn_connection_test.go index 709e84c872..21af837ccc 100644 --- a/builtin/providers/aws/resource_aws_vpn_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpn_connection_test.go @@ -15,6 +15,7 @@ import ( func TestAccAWSVpnConnection_basic(t *testing.T) { rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_vpn_connection.foo", @@ -22,7 +23,7 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { CheckDestroy: testAccAwsVpnConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsVpnConnectionConfig, + Config: testAccAwsVpnConnectionConfig(rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", @@ -33,7 +34,7 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { ), }, { - Config: testAccAwsVpnConnectionConfigUpdate(rInt), + Config: testAccAwsVpnConnectionConfigUpdate(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", @@ -49,6 +50,7 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { func TestAccAWSVpnConnection_withoutStaticRoutes(t *testing.T) { rInt := acctest.RandInt() + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_vpn_connection.foo", @@ -56,7 +58,7 @@ func TestAccAWSVpnConnection_withoutStaticRoutes(t *testing.T) { CheckDestroy: testAccAwsVpnConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsVpnConnectionConfigUpdate(rInt), + Config: testAccAwsVpnConnectionConfigUpdate(rInt, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", @@ -163,32 +165,34 @@ func TestAWSVpnConnection_xmlconfig(t *testing.T) { } } -const testAccAwsVpnConnectionConfig = ` - resource "aws_vpn_gateway" "vpn_gateway" { - tags { - Name = "vpn_gateway" - } - } - - resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 - ip_address = "178.0.0.1" - type = "ipsec.1" - tags { - Name = "main-customer-gateway" +func testAccAwsVpnConnectionConfig(rBgpAsn int) string { + return fmt.Sprintf(` + resource "aws_vpn_gateway" "vpn_gateway" { + tags { + Name = "vpn_gateway" + } } - } - resource "aws_vpn_connection" "foo" { - vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" - customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" - type = "ipsec.1" - static_routes_only = true - } - ` + resource "aws_customer_gateway" "customer_gateway" { + bgp_asn = %d + ip_address = "178.0.0.1" + type = "ipsec.1" + tags { + Name = "main-customer-gateway" + } + } + + resource "aws_vpn_connection" "foo" { + vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" + customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" + type = "ipsec.1" + static_routes_only = true + } + `, rBgpAsn) +} // Change static_routes_only to be false, forcing a refresh. -func testAccAwsVpnConnectionConfigUpdate(rInt int) string { +func testAccAwsVpnConnectionConfigUpdate(rInt, rBgpAsn int) string { return fmt.Sprintf(` resource "aws_vpn_gateway" "vpn_gateway" { tags { @@ -197,7 +201,7 @@ func testAccAwsVpnConnectionConfigUpdate(rInt int) string { } resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 + bgp_asn = %d ip_address = "178.0.0.1" type = "ipsec.1" tags { @@ -211,7 +215,7 @@ func testAccAwsVpnConnectionConfigUpdate(rInt int) string { type = "ipsec.1" static_routes_only = false } - `, rInt) + `, rBgpAsn, rInt) } // Test our VPN tunnel config XML parsing diff --git a/builtin/providers/aws/resource_vpn_connection_route_test.go b/builtin/providers/aws/resource_vpn_connection_route_test.go index 24e0480039..23229b0f9b 100644 --- a/builtin/providers/aws/resource_vpn_connection_route_test.go +++ b/builtin/providers/aws/resource_vpn_connection_route_test.go @@ -8,18 +8,20 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSVpnConnectionRoute_basic(t *testing.T) { + rBgpAsn := acctest.RandIntRange(64512, 65534) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccAwsVpnConnectionRouteDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAwsVpnConnectionRouteConfig, + Config: testAccAwsVpnConnectionRouteConfig(rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnectionRoute( "aws_vpn_gateway.vpn_gateway", @@ -30,7 +32,7 @@ func TestAccAWSVpnConnectionRoute_basic(t *testing.T) { ), }, resource.TestStep{ - Config: testAccAwsVpnConnectionRouteConfigUpdate, + Config: testAccAwsVpnConnectionRouteConfigUpdate(rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnectionRoute( "aws_vpn_gateway.vpn_gateway", @@ -143,55 +145,59 @@ func testAccAwsVpnConnectionRoute( } } -const testAccAwsVpnConnectionRouteConfig = ` -resource "aws_vpn_gateway" "vpn_gateway" { - tags { - Name = "vpn_gateway" +func testAccAwsVpnConnectionRouteConfig(rBgpAsn int) string { + return fmt.Sprintf(` + resource "aws_vpn_gateway" "vpn_gateway" { + tags { + Name = "vpn_gateway" + } } -} -resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 - ip_address = "182.0.0.1" - type = "ipsec.1" -} + resource "aws_customer_gateway" "customer_gateway" { + bgp_asn = %d + ip_address = "182.0.0.1" + type = "ipsec.1" + } -resource "aws_vpn_connection" "vpn_connection" { - vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" - customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" - type = "ipsec.1" - static_routes_only = true -} + resource "aws_vpn_connection" "vpn_connection" { + vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" + customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" + type = "ipsec.1" + static_routes_only = true + } -resource "aws_vpn_connection_route" "foo" { - destination_cidr_block = "172.168.10.0/24" - vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" + resource "aws_vpn_connection_route" "foo" { + destination_cidr_block = "172.168.10.0/24" + vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" + } + `, rBgpAsn) } -` // Change destination_cidr_block -const testAccAwsVpnConnectionRouteConfigUpdate = ` -resource "aws_vpn_gateway" "vpn_gateway" { - tags { - Name = "vpn_gateway" +func testAccAwsVpnConnectionRouteConfigUpdate(rBgpAsn int) string { + return fmt.Sprintf(` + resource "aws_vpn_gateway" "vpn_gateway" { + tags { + Name = "vpn_gateway" + } } -} -resource "aws_customer_gateway" "customer_gateway" { - bgp_asn = 65000 - ip_address = "182.0.0.1" - type = "ipsec.1" -} + resource "aws_customer_gateway" "customer_gateway" { + bgp_asn = %d + ip_address = "182.0.0.1" + type = "ipsec.1" + } -resource "aws_vpn_connection" "vpn_connection" { - vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" - customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" - type = "ipsec.1" - static_routes_only = true -} + resource "aws_vpn_connection" "vpn_connection" { + vpn_gateway_id = "${aws_vpn_gateway.vpn_gateway.id}" + customer_gateway_id = "${aws_customer_gateway.customer_gateway.id}" + type = "ipsec.1" + static_routes_only = true + } -resource "aws_vpn_connection_route" "foo" { - destination_cidr_block = "172.168.20.0/24" - vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" + resource "aws_vpn_connection_route" "foo" { + destination_cidr_block = "172.168.20.0/24" + vpn_connection_id = "${aws_vpn_connection.vpn_connection.id}" + } + `, rBgpAsn) } -` From 35ceeb15f4d43b74550466c27c57bab6914465d2 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 3 Apr 2017 13:27:43 -0600 Subject: [PATCH 6/7] final fix after merge with master --- builtin/providers/aws/resource_aws_customer_gateway_test.go | 1 - builtin/providers/aws/resource_aws_vpn_connection_test.go | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_customer_gateway_test.go b/builtin/providers/aws/resource_aws_customer_gateway_test.go index b6e33984d9..9606a45571 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway_test.go +++ b/builtin/providers/aws/resource_aws_customer_gateway_test.go @@ -75,7 +75,6 @@ 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, diff --git a/builtin/providers/aws/resource_aws_vpn_connection_test.go b/builtin/providers/aws/resource_aws_vpn_connection_test.go index 49b0c0e510..c5b9c45815 100644 --- a/builtin/providers/aws/resource_aws_vpn_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpn_connection_test.go @@ -81,6 +81,7 @@ func TestAccAWSVpnConnection_withoutStaticRoutes(t *testing.T) { } func TestAccAWSVpnConnection_disappears(t *testing.T) { + rBgpAsn := acctest.RandIntRange(64512, 65534) var vpn ec2.VpnConnection resource.Test(t, resource.TestCase{ @@ -89,7 +90,7 @@ func TestAccAWSVpnConnection_disappears(t *testing.T) { CheckDestroy: testAccAwsVpnConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsVpnConnectionConfig, + Config: testAccAwsVpnConnectionConfig(rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccAwsVpnConnection( "aws_vpc.vpc", From 2697532c8f4f4c322c5a982bc6854265114d5f37 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 4 Apr 2017 11:07:55 +0100 Subject: [PATCH 7/7] aws: Randomize IAM policy name in acc test --- .../providers/aws/resource_aws_iam_policy_attachment_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e2e9c2a8ed..6ae57b1d52 100644 --- a/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_policy_attachment_test.go @@ -310,7 +310,7 @@ resource "aws_iam_user" "user" { name = "${format("paged-test-user-%d-%%d", count.index + 1)}" } resource "aws_iam_policy" "policy" { - name = "test-policy" + name = "tf-acc-test-policy-%d" description = "A test policy" policy = <