Skip to content

Commit

Permalink
tests/provider: Remove hardcoded us-west-2 provider declaration… (#9075)
Browse files Browse the repository at this point in the history
Reference: #8983

Test configurations should omit `provider "aws"` declarations as these:

* Prevents the same configuration from successfully running against multiple AWS partitions (e.g. AWS Commercial and AWS GovCloud (US))
* Reconfigure the default testing provider configuration, which can cause unexpected behavior across multiple tests

In this pass, we cleanup the trivial cases of `region = "us-west-2"` declarations, which matches the default region the acceptance testing framework is configured. As an added benefit of these changes, some of these tests may begin passing in AWS GovCloud (US) and other partitions. Future updates will handle hardcoded region and availability zone testing.

Previously from `tfproviderlint -AT004 ./aws` (only relevant failures shown):

```
aws/data_source_aws_availability_zone_test.go:35:52: AT004: provider declaration should be omitted
aws/data_source_aws_canonical_user_id_test.go:44:51: AT004: provider declaration should be omitted
aws/data_source_aws_kms_ciphertext_test.go:57:55: AT004: provider declaration should be omitted
aws/data_source_aws_kms_ciphertext_test.go:74:58: AT004: provider declaration should be omitted
aws/data_source_aws_kms_ciphertext_test.go:92:70: AT004: provider declaration should be omitted
aws/data_source_aws_nat_gateway_test.go:45:21: AT004: provider declaration should be omitted
aws/data_source_aws_prefix_list_test.go:60:46: AT004: provider declaration should be omitted
aws/data_source_aws_sns_test.go:52:44: AT004: provider declaration should be omitted
aws/data_source_aws_vpc_test.go:134:21: AT004: provider declaration should be omitted
aws/data_source_aws_vpc_test.go:155:21: AT004: provider declaration should be omitted
aws/resource_aws_autoscaling_group_test.go:2481:67: AT004: provider declaration should be omitted
aws/resource_aws_autoscaling_group_test.go:2624:21: AT004: provider declaration should be omitted
aws/resource_aws_default_route_table_test.go:241:41: AT004: provider declaration should be omitted
aws/resource_aws_default_route_table_test.go:291:45: AT004: provider declaration should be omitted
aws/resource_aws_default_route_table_test.go:384:47: AT004: provider declaration should be omitted
aws/resource_aws_default_vpc_test.go:50:41: AT004: provider declaration should be omitted
aws/resource_aws_elb_test.go:1680:37: AT004: provider declaration should be omitted
aws/resource_aws_elb_test.go:1751:41: AT004: provider declaration should be omitted
aws/resource_aws_opsworks_custom_layer_test.go:349:21: AT004: provider declaration should be omitted
aws/resource_aws_opsworks_rails_app_layer_test.go:79:21: AT004: provider declaration should be omitted
aws/resource_aws_opsworks_rails_app_layer_test.go:103:21: AT004: provider declaration should be omitted
aws/resource_aws_opsworks_stack_test.go:726:21: AT004: provider declaration should be omitted
aws/resource_aws_opsworks_stack_test.go:819:21: AT004: provider declaration should be omitted
aws/resource_aws_subnet_test.go:456:47: AT004: provider declaration should be omitted
aws/resource_aws_vpc_endpoint_route_table_association_test.go:105:55: AT004: provider declaration should be omitted
```

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups (81.06s)
--- PASS: TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity (372.99s)
--- PASS: TestAccAWSDefaultRouteTable_basic (77.18s)
--- PASS: TestAccAWSDefaultRouteTable_Route_TransitGatewayID (314.28s)
--- PASS: TestAccAWSDefaultRouteTable_swap (62.06s)
--- PASS: TestAccAWSDefaultRouteTable_vpc_endpoint (44.30s)
--- PASS: TestAccAWSDefaultVpc_basic (23.95s)
--- PASS: TestAccAWSELB_swap_subnets (74.50s)
--- PASS: TestAccAWSOpsworksCustomLayer_importBasic (42.93s)
--- PASS: TestAccAWSOpsworksRailsAppLayer (59.16s)
--- PASS: TestAccAWSOpsworksStackNoVpcCreateTags (36.37s)
--- PASS: TestAccAWSSubnet_availabilityZoneId (32.60s)
--- PASS: TestAccAWSVpcEndpointRouteTableAssociation_basic (44.86s)
--- PASS: TestAccDataSourceAwsAvailabilityZone (12.31s)
--- PASS: TestAccDataSourceAwsCanonicalUserId_basic (11.20s)
--- PASS: TestAccDataSourceAwsKmsCiphertext_basic (39.08s)
--- PASS: TestAccDataSourceAwsKmsCiphertext_validate (39.13s)
--- PASS: TestAccDataSourceAwsKmsCiphertext_validate_withContext (39.34s)
--- PASS: TestAccDataSourceAwsNatGateway (215.82s)
--- PASS: TestAccDataSourceAwsPrefixList (11.04s)
--- PASS: TestAccDataSourceAwsSnsTopic (14.32s)
--- PASS: TestAccDataSourceAwsVpc_basic (36.01s)
--- PASS: TestAccDataSourceAwsVpc_ipv6Associated (34.89s)
--- PASS: TestAccDataSourceAwsVpc_multipleCidr (53.00s)
```
  • Loading branch information
bflad authored and nywilken committed Jul 10, 2019
1 parent 577ed78 commit 29c41d7
Show file tree
Hide file tree
Showing 16 changed files with 0 additions and 100 deletions.
4 changes: 0 additions & 4 deletions aws/data_source_aws_availability_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ func TestAccDataSourceAwsAvailabilityZone(t *testing.T) {
}

const testAccDataSourceAwsAvailabilityZoneConfig = `
provider "aws" {
region = "us-west-2"
}
data "aws_availability_zone" "by_name" {
name = "us-west-2a"
}
Expand Down
4 changes: 0 additions & 4 deletions aws/data_source_aws_canonical_user_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,5 @@ func testAccDataSourceAwsCanonicalUserIdCheckExists(name string) resource.TestCh
}

const testAccDataSourceAwsCanonicalUserIdConfig = `
provider "aws" {
region = "us-west-2"
}
data "aws_canonical_user_id" "current" { }
`
12 changes: 0 additions & 12 deletions aws/data_source_aws_kms_ciphertext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func TestAccDataSourceAwsKmsCiphertext_validate_withContext(t *testing.T) {
}

const testAccDataSourceAwsKmsCiphertextConfig_basic = `
provider "aws" {
region = "us-west-2"
}
resource "aws_kms_key" "foo" {
description = "tf-test-acc-data-source-aws-kms-ciphertext-basic"
is_enabled = true
Expand All @@ -72,10 +68,6 @@ data "aws_kms_ciphertext" "foo" {
`

const testAccDataSourceAwsKmsCiphertextConfig_validate = `
provider "aws" {
region = "us-west-2"
}
resource "aws_kms_key" "foo" {
description = "tf-test-acc-data-source-aws-kms-ciphertext-validate"
is_enabled = true
Expand All @@ -90,10 +82,6 @@ data "aws_kms_ciphertext" "foo" {
`

const testAccDataSourceAwsKmsCiphertextConfig_validate_withContext = `
provider "aws" {
region = "us-west-2"
}
resource "aws_kms_key" "foo" {
description = "tf-test-acc-data-source-aws-kms-ciphertext-validate-with-context"
is_enabled = true
Expand Down
4 changes: 0 additions & 4 deletions aws/data_source_aws_nat_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func TestAccDataSourceAwsNatGateway(t *testing.T) {

func testAccDataSourceAwsNatGatewayConfig(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "172.%d.0.0/16"
Expand Down
4 changes: 0 additions & 4 deletions aws/data_source_aws_prefix_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ func testAccDataSourceAwsPrefixListCheck(name string) resource.TestCheckFunc {
}

const testAccDataSourceAwsPrefixListConfig = `
provider "aws" {
region = "us-west-2"
}
data "aws_prefix_list" "s3_by_id" {
prefix_list_id = "pl-68a54001"
}
Expand Down
4 changes: 0 additions & 4 deletions aws/data_source_aws_sns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func testAccDataSourceAwsSnsTopicCheck(name string) resource.TestCheckFunc {
}

const testAccDataSourceAwsSnsTopicConfig = `
provider "aws" {
region = "us-west-2"
}
resource "aws_sns_topic" "tf_wrong1" {
name = "wrong1"
}
Expand Down
8 changes: 0 additions & 8 deletions aws/data_source_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ func TestAccDataSourceAwsVpc_multipleCidr(t *testing.T) {

func testAccDataSourceAwsVpcConfigIpv6(cidr, tag string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "%s"
assign_generated_ipv6_cidr_block = true
Expand All @@ -153,10 +149,6 @@ data "aws_vpc" "by_id" {

func testAccDataSourceAwsVpcConfig(cidr, tag string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "%s"
Expand Down
8 changes: 0 additions & 8 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2479,10 +2479,6 @@ resource "aws_security_group" "tf_test_self" {
`

const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post_duo = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
Expand Down Expand Up @@ -2622,10 +2618,6 @@ resource "aws_autoscaling_group" "bar" {

func testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = "true"
Expand Down
12 changes: 0 additions & 12 deletions aws/resource_aws_default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ resource "aws_internet_gateway" "gw" {
}`

const testAccDefaultRouteTable_change = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
Expand Down Expand Up @@ -289,10 +285,6 @@ resource "aws_route_table" "r" {
`

const testAccDefaultRouteTable_change_mod = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
Expand Down Expand Up @@ -382,10 +374,6 @@ resource "aws_default_route_table" "test" {
}

const testAccDefaultRouteTable_vpc_endpoint = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
Expand Down
4 changes: 0 additions & 4 deletions aws/resource_aws_default_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func testAccCheckAWSDefaultVpcDestroy(s *terraform.State) error {
}

const testAccAWSDefaultVpcConfigBasic = `
provider "aws" {
region = "us-west-2"
}
resource "aws_default_vpc" "foo" {
tags = {
Name = "Default VPC"
Expand Down
8 changes: 0 additions & 8 deletions aws/resource_aws_elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,10 +1678,6 @@ resource "aws_elb" "bar" {
}

const testAccAWSELBConfig_subnets = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "azelb" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
Expand Down Expand Up @@ -1749,10 +1745,6 @@ resource "aws_internet_gateway" "gw" {
`

const testAccAWSELBConfig_subnet_swap = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "azelb" {
cidr_block = "10.1.0.0/16"
enable_dns_hostnames = true
Expand Down
4 changes: 0 additions & 4 deletions aws/resource_aws_opsworks_custom_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ resource "aws_opsworks_custom_layer" "tf-acc" {

func testAccAwsOpsworksCustomLayerConfigVpcCreate(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_custom_layer" "tf-acc" {
stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "%s"
Expand Down
8 changes: 0 additions & 8 deletions aws/resource_aws_opsworks_rails_app_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ func testAccCheckAwsOpsworksRailsAppLayerDestroy(s *terraform.State) error {

func testAccAwsOpsworksRailsAppLayerConfigVpcCreate(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_rails_app_layer" "tf-acc" {
stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "%s"
Expand All @@ -101,10 +97,6 @@ resource "aws_opsworks_rails_app_layer" "tf-acc" {

func testAccAwsOpsworksRailsAppLayerNoManageBundlerConfigVpcCreate(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_rails_app_layer" "tf-acc" {
stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "%s"
Expand Down
8 changes: 0 additions & 8 deletions aws/resource_aws_opsworks_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,6 @@ resource "aws_iam_instance_profile" "opsworks_instance" {

func testAccAwsOpsworksStackConfigNoVpcCreateTags(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_stack" "tf-acc" {
name = "%s"
region = "us-west-2"
Expand Down Expand Up @@ -817,10 +813,6 @@ resource "aws_iam_instance_profile" "opsworks_instance" {

func testAccAwsOpsworksStackConfigNoVpcUpdateTags(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_stack" "tf-acc" {
name = "%s"
region = "us-west-2"
Expand Down
4 changes: 0 additions & 4 deletions aws/resource_aws_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,6 @@ resource "aws_subnet" "foo" {
`

const testAccSubnetConfigAvailabilityZoneId = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
tags = {
Expand Down
4 changes: 0 additions & 4 deletions aws/resource_aws_vpc_endpoint_route_table_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ func testAccCheckVpcEndpointRouteTableAssociationExists(n string, vpce *ec2.VpcE
}

const testAccVpcEndpointRouteTableAssociationConfig = `
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16"
tags = {
Expand Down

0 comments on commit 29c41d7

Please sign in to comment.