Skip to content

Commit

Permalink
provider: First pass at removing non-inclusive terminology (#13771)
Browse files Browse the repository at this point in the history
* provider: First pass at removing non-inclusive terminology

Reference: #13766

Changes:

* data-source/aws_availability_zones: Deprecate blacklisted_ arguments for skip_ arguments

Output from acceptance testing:

```
--- PASS: TestAccAWSAvailabilityZones_stateFilter (16.19s)
--- PASS: TestAccAWSAvailabilityZones_AllAvailabilityZones (16.22s)
--- PASS: TestAccAWSAvailabilityZones_Filter (16.33s)
--- PASS: TestAccAWSAvailabilityZones_basic (16.52s)
--- PASS: TestAccAWSAvailabilityZones_SkipZoneIds (17.68s)
--- PASS: TestAccAWSAvailabilityZones_BlacklistedZoneIds (17.75s)
--- PASS: TestAccAWSAvailabilityZones_BlacklistedNames (18.07s)
--- PASS: TestAccAWSAvailabilityZones_SkipNames (18.19s)
```

* docs/provider: Add aws_availability_zones removals to version 3 guide

* data-source/aws_availability_zones: Switch skip_* naming to exclude_*

Output from acceptance testing:

```
--- PASS: TestAccAWSAvailabilityZones_AllAvailabilityZones (18.12s)
--- PASS: TestAccAWSAvailabilityZones_stateFilter (18.20s)
--- PASS: TestAccAWSAvailabilityZones_Filter (18.30s)
--- PASS: TestAccAWSAvailabilityZones_basic (18.32s)
--- PASS: TestAccAWSAvailabilityZones_ExcludeZoneIds (19.82s)
--- PASS: TestAccAWSAvailabilityZones_ExcludeNames (20.00s)
--- PASS: TestAccAWSAvailabilityZones_BlacklistedNames (20.04s)
--- PASS: TestAccAWSAvailabilityZones_BlacklistedZoneIds (20.14s)
```
  • Loading branch information
bflad authored Jun 26, 2020
1 parent ae05ef9 commit 23066a5
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 115 deletions.
35 changes: 27 additions & 8 deletions aws/data_source_aws_availability_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ func dataSourceAwsAvailabilityZones() *schema.Resource {
Optional: true,
},
"blacklisted_names": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"exclude_names"},
Deprecated: "use `exclude_names` instead",
Elem: &schema.Schema{Type: schema.TypeString},
},
"blacklisted_zone_ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"exclude_zone_ids"},
Deprecated: "use `exclude_zone_ids` instead",
Elem: &schema.Schema{Type: schema.TypeString},
},
"filter": ec2CustomFiltersSchema(),
"group_names": {
Expand All @@ -42,6 +46,18 @@ func dataSourceAwsAvailabilityZones() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"exclude_names": {
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"blacklisted_names"},
Elem: &schema.Schema{Type: schema.TypeString},
},
"exclude_zone_ids": {
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"blacklisted_zone_ids"},
Elem: &schema.Schema{Type: schema.TypeString},
},
"state": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -105,6 +121,9 @@ func dataSourceAwsAvailabilityZonesRead(d *schema.ResourceData, meta interface{}

blacklistedNames := d.Get("blacklisted_names").(*schema.Set)
blacklistedZoneIDs := d.Get("blacklisted_zone_ids").(*schema.Set)
excludeNames := d.Get("exclude_names").(*schema.Set)
excludeZoneIDs := d.Get("exclude_zone_ids").(*schema.Set)

groupNames := schema.NewSet(schema.HashString, nil)
names := []string{}
zoneIds := []string{}
Expand All @@ -113,11 +132,11 @@ func dataSourceAwsAvailabilityZonesRead(d *schema.ResourceData, meta interface{}
name := aws.StringValue(v.ZoneName)
zoneID := aws.StringValue(v.ZoneId)

if blacklistedNames.Contains(name) {
if blacklistedNames.Contains(name) || excludeNames.Contains(name) {
continue
}

if blacklistedZoneIDs.Contains(zoneID) {
if blacklistedZoneIDs.Contains(zoneID) || excludeZoneIDs.Contains(zoneID) {
continue
}

Expand Down
76 changes: 66 additions & 10 deletions aws/data_source_aws_availability_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestAccAWSAvailabilityZones_AllAvailabilityZones(t *testing.T) {

func TestAccAWSAvailabilityZones_BlacklistedNames(t *testing.T) {
allDataSourceName := "data.aws_availability_zones.all"
blacklistedDataSourceName := "data.aws_availability_zones.test"
excludeDataSourceName := "data.aws_availability_zones.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -116,7 +116,7 @@ func TestAccAWSAvailabilityZones_BlacklistedNames(t *testing.T) {
{
Config: testAccCheckAwsAvailabilityZonesConfigBlacklistedNames(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAvailabilityZonesBlacklisting(allDataSourceName, blacklistedDataSourceName),
testAccCheckAwsAvailabilityZonesExcluded(allDataSourceName, excludeDataSourceName),
),
},
},
Expand All @@ -125,7 +125,7 @@ func TestAccAWSAvailabilityZones_BlacklistedNames(t *testing.T) {

func TestAccAWSAvailabilityZones_BlacklistedZoneIds(t *testing.T) {
allDataSourceName := "data.aws_availability_zones.all"
blacklistedDataSourceName := "data.aws_availability_zones.test"
excludeDataSourceName := "data.aws_availability_zones.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -134,7 +134,7 @@ func TestAccAWSAvailabilityZones_BlacklistedZoneIds(t *testing.T) {
{
Config: testAccCheckAwsAvailabilityZonesConfigBlacklistedZoneIds(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAvailabilityZonesBlacklisting(allDataSourceName, blacklistedDataSourceName),
testAccCheckAwsAvailabilityZonesExcluded(allDataSourceName, excludeDataSourceName),
),
},
},
Expand All @@ -158,6 +158,42 @@ func TestAccAWSAvailabilityZones_Filter(t *testing.T) {
})
}

func TestAccAWSAvailabilityZones_ExcludeNames(t *testing.T) {
allDataSourceName := "data.aws_availability_zones.all"
excludeDataSourceName := "data.aws_availability_zones.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsAvailabilityZonesConfigExcludeNames(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAvailabilityZonesExcluded(allDataSourceName, excludeDataSourceName),
),
},
},
})
}

func TestAccAWSAvailabilityZones_ExcludeZoneIds(t *testing.T) {
allDataSourceName := "data.aws_availability_zones.all"
excludeDataSourceName := "data.aws_availability_zones.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsAvailabilityZonesConfigExcludeZoneIds(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAvailabilityZonesExcluded(allDataSourceName, excludeDataSourceName),
),
},
},
})
}

func TestAccAWSAvailabilityZones_stateFilter(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -198,16 +234,16 @@ func testAccCheckAwsAvailabilityZonesMeta(n string) resource.TestCheckFunc {
}
}

func testAccCheckAwsAvailabilityZonesBlacklisting(allDataSourceName, blacklistedDataSourceName string) resource.TestCheckFunc {
func testAccCheckAwsAvailabilityZonesExcluded(allDataSourceName, excludeDataSourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
allResourceState, ok := s.RootModule().Resources[allDataSourceName]
if !ok {
return fmt.Errorf("Resource does not exist: %s", allDataSourceName)
}

blacklistedResourceState, ok := s.RootModule().Resources[blacklistedDataSourceName]
excludeResourceState, ok := s.RootModule().Resources[excludeDataSourceName]
if !ok {
return fmt.Errorf("Resource does not exist: %s", blacklistedDataSourceName)
return fmt.Errorf("Resource does not exist: %s", excludeDataSourceName)
}

for _, attribute := range []string{"names.#", "zone_ids.#"} {
Expand All @@ -217,13 +253,13 @@ func testAccCheckAwsAvailabilityZonesBlacklisting(allDataSourceName, blacklisted
return fmt.Errorf("cannot find %s in %s resource state attributes: %+v", attribute, allDataSourceName, allResourceState.Primary.Attributes)
}

blacklistedValue, ok := blacklistedResourceState.Primary.Attributes[attribute]
excludeValue, ok := excludeResourceState.Primary.Attributes[attribute]

if !ok {
return fmt.Errorf("cannot find %s in %s resource state attributes: %+v", attribute, blacklistedDataSourceName, blacklistedResourceState.Primary.Attributes)
return fmt.Errorf("cannot find %s in %s resource state attributes: %+v", attribute, excludeDataSourceName, excludeResourceState.Primary.Attributes)
}

if allValue == blacklistedValue {
if allValue == excludeValue {
return fmt.Errorf("expected %s attribute value difference, got: %s", attribute, allValue)
}
}
Expand Down Expand Up @@ -338,6 +374,26 @@ data "aws_availability_zones" "test" {
`)
}

func testAccCheckAwsAvailabilityZonesConfigExcludeNames() string {
return fmt.Sprintf(`
data "aws_availability_zones" "all" {}
data "aws_availability_zones" "test" {
exclude_names = ["${data.aws_availability_zones.all.names[0]}"]
}
`)
}

func testAccCheckAwsAvailabilityZonesConfigExcludeZoneIds() string {
return fmt.Sprintf(`
data "aws_availability_zones" "all" {}
data "aws_availability_zones" "test" {
exclude_zone_ids = ["${data.aws_availability_zones.all.zone_ids[0]}"]
}
`)
}

const testAccCheckAwsAvailabilityZonesStateConfig = `
data "aws_availability_zones" "state_filter" {
state = "available"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func testAccAWSEc2TransitGatewayVpcAttachmentDataSourceConfigFilter() string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# IncorrectState: Transit Gateway is not available in availability zone us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -109,8 +109,8 @@ func testAccAWSEc2TransitGatewayVpcAttachmentDataSourceConfigID() string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# IncorrectState: Transit Gateway is not available in availability zone us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ data "aws_eip" "test" {
const testAccDataSourceAwsEipConfigInstance = `
data "aws_availability_zones" "available" {
# Error launching source instance: Unsupported: Your requested instance type (t2.micro) is not supported in your requested Availability Zone (us-west-2d).
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func testAccAWSRouteDataSourceConfigTransitGatewayID() string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# IncorrectState: Transit Gateway is not available in availability zone us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_appautoscaling_scheduled_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func testAccAppautoscalingScheduledActionConfig_EMR(rName, ts string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# The requested instance type c4.large is not supported in the requested availability zone.
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_appautoscaling_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ func testAccAWSAppautoscalingTargetEmrClusterConfig(rInt int) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# The requested instance type m3.xlarge is not supported in the requested availability zone.
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
24 changes: 12 additions & 12 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ data "aws_ami" "test" {
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -2418,8 +2418,8 @@ resource "aws_internet_gateway" "gw" {
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -2523,8 +2523,8 @@ resource "aws_internet_gateway" "gw" {
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -3491,8 +3491,8 @@ resource "aws_vpc" "test" {
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -3778,8 +3778,8 @@ data "aws_ami" "test" {
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -4202,8 +4202,8 @@ func testAccAWSAutoScalingGroupPartitionConfig(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# t2.micro is not supported in us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_cloud9_environment_ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ func testAccAWSCloud9EnvironmentEc2ConfigBase() string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# t2.micro instance type is not available in these Availability Zones
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_codebuild_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3397,8 +3397,8 @@ func testAccAWSCodeBuildProjectConfig_VpcConfig1(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
data "aws_availability_zones" "available" {
# InvalidInputException: CodeBuild currently doesn't support VPC in us-west-2d, please select subnets in other availability zones.
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down Expand Up @@ -3458,8 +3458,8 @@ func testAccAWSCodeBuildProjectConfig_VpcConfig2(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
data "aws_availability_zones" "available" {
# InvalidInputException: CodeBuild currently doesn't support VPC in us-west-2d, please select subnets in other availability zones.
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_ec2_client_vpn_network_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func testAccEc2ClientVpnNetworkAssociationConfig(rName string) string {
return testAccEc2ClientVpnNetworkAssociationConfigAcmCertificateBase() + fmt.Sprintf(`
data "aws_availability_zones" "available" {
# InvalidParameterValue: AZ us-west-2d is not currently supported. Please choose another az in this region
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_ec2_transit_gateway_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func testAccAWSEc2TransitGatewayRouteConfigDestinationCidrBlock() string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# IncorrectState: Transit Gateway is not available in availability zone us-west-2d
blacklisted_zone_ids = ["usw2-az4"]
state = "available"
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
Expand Down
Loading

0 comments on commit 23066a5

Please sign in to comment.