-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service/ec2: Initial support for Local Zones
Reference: #11136 Reference: #11994 Changes: * New Resource: `aws_ec2_availability_zone_group` * data-source/aws_availability_zone: Add `all_availability_zones` and `filter` arguments * data-source/aws_availability_zone: Add `group_name`, `network_border_group`, and `opt_in_status` attributes * data-source/aws_availability_zones: Add `all_availability_zones` and `filter` arguments * data-source/aws_availability_zones: Add `group_names` attribute ``` --- PASS: TestAccDataSourceAwsAvailabilityZone_Filter (17.53s) --- PASS: TestAccDataSourceAwsAvailabilityZone_ZoneId (17.74s) --- PASS: TestAccDataSourceAwsAvailabilityZone_AllAvailabilityZones (17.74s) --- PASS: TestAccDataSourceAwsAvailabilityZone_Name (17.79s) --- PASS: TestAccAWSAvailabilityZones_Filter (15.46s) --- PASS: TestAccAWSAvailabilityZones_stateFilter (15.87s) --- PASS: TestAccAWSAvailabilityZones_basic (16.60s) --- PASS: TestAccAWSAvailabilityZones_AllAvailabilityZones (16.70s) --- PASS: TestAccAWSAvailabilityZones_BlacklistedNames (17.00s) --- PASS: TestAccAWSAvailabilityZones_BlacklistedZoneIds (17.14s) --- PASS: TestAccAWSEc2AvailabilityZoneGroup_OptInStatus (37.67s) ```
- Loading branch information
Showing
11 changed files
with
636 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,149 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsAvailabilityZone(t *testing.T) { | ||
ds1ResourceName := "data.aws_availability_zone.by_name" | ||
ds2ResourceName := "data.aws_availability_zone.by_zone_id" | ||
func TestAccDataSourceAwsAvailabilityZone_AllAvailabilityZones(t *testing.T) { | ||
availabilityZonesDataSourceName := "data.aws_availability_zones.test" | ||
dataSourceName := "data.aws_availability_zone.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsAvailabilityZoneConfig, | ||
Config: testAccDataSourceAwsAvailabilityZoneConfigAllAvailabilityZones(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(ds1ResourceName, "name", "us-west-2a"), | ||
resource.TestCheckResourceAttr(ds1ResourceName, "name_suffix", "a"), | ||
resource.TestCheckResourceAttr(ds1ResourceName, "region", "us-west-2"), | ||
resource.TestCheckResourceAttrSet(ds1ResourceName, "zone_id"), | ||
|
||
resource.TestCheckResourceAttr(ds2ResourceName, "name", "us-west-2a"), | ||
resource.TestCheckResourceAttr(ds2ResourceName, "name_suffix", "a"), | ||
resource.TestCheckResourceAttr(ds2ResourceName, "region", "us-west-2"), | ||
resource.TestCheckResourceAttrPair(ds2ResourceName, "zone_id", ds1ResourceName, "zone_id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "group_name", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", availabilityZonesDataSourceName, "names.0"), | ||
resource.TestMatchResourceAttr(dataSourceName, "name_suffix", regexp.MustCompile(`^[a-z]$`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "network_border_group", testAccGetRegion()), | ||
resource.TestCheckResourceAttr(dataSourceName, "opt_in_status", "opt-in-not-required"), | ||
resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", availabilityZonesDataSourceName, "zone_ids.0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourceAwsAvailabilityZoneConfig = ` | ||
data "aws_availability_zone" "by_name" { | ||
name = "us-west-2a" | ||
func TestAccDataSourceAwsAvailabilityZone_Filter(t *testing.T) { | ||
availabilityZonesDataSourceName := "data.aws_availability_zones.test" | ||
dataSourceName := "data.aws_availability_zone.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsAvailabilityZoneConfigFilter(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "group_name", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", availabilityZonesDataSourceName, "names.0"), | ||
resource.TestMatchResourceAttr(dataSourceName, "name_suffix", regexp.MustCompile(`^[a-z]$`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "network_border_group", testAccGetRegion()), | ||
resource.TestCheckResourceAttr(dataSourceName, "opt_in_status", "opt-in-not-required"), | ||
resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", availabilityZonesDataSourceName, "zone_ids.0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAwsAvailabilityZone_Name(t *testing.T) { | ||
availabilityZonesDataSourceName := "data.aws_availability_zones.test" | ||
dataSourceName := "data.aws_availability_zone.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsAvailabilityZoneConfigName(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "group_name", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", availabilityZonesDataSourceName, "names.0"), | ||
resource.TestMatchResourceAttr(dataSourceName, "name_suffix", regexp.MustCompile(`^[a-z]$`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "network_border_group", testAccGetRegion()), | ||
resource.TestCheckResourceAttr(dataSourceName, "opt_in_status", "opt-in-not-required"), | ||
resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", availabilityZonesDataSourceName, "zone_ids.0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
data "aws_availability_zone" "by_zone_id" { | ||
zone_id = "${data.aws_availability_zone.by_name.zone_id}" | ||
func TestAccDataSourceAwsAvailabilityZone_ZoneId(t *testing.T) { | ||
availabilityZonesDataSourceName := "data.aws_availability_zones.test" | ||
dataSourceName := "data.aws_availability_zone.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsAvailabilityZoneConfigZoneId(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "group_name", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", availabilityZonesDataSourceName, "names.0"), | ||
resource.TestMatchResourceAttr(dataSourceName, "name_suffix", regexp.MustCompile(`^[a-z]$`)), | ||
resource.TestCheckResourceAttr(dataSourceName, "network_border_group", testAccGetRegion()), | ||
resource.TestCheckResourceAttr(dataSourceName, "opt_in_status", "opt-in-not-required"), | ||
resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", availabilityZonesDataSourceName, "zone_ids.0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsAvailabilityZoneConfigAllAvailabilityZones() string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "test" {} | ||
data "aws_availability_zone" "test" { | ||
all_availability_zones = true | ||
name = data.aws_availability_zones.test.names[0] | ||
} | ||
`) | ||
} | ||
|
||
func testAccDataSourceAwsAvailabilityZoneConfigFilter() string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "test" {} | ||
data "aws_availability_zone" "test" { | ||
filter { | ||
name = "zone-name" | ||
values = [data.aws_availability_zones.test.names[0]] | ||
} | ||
} | ||
`) | ||
} | ||
|
||
func testAccDataSourceAwsAvailabilityZoneConfigName() string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "test" {} | ||
data "aws_availability_zone" "test" { | ||
name = data.aws_availability_zones.test.names[0] | ||
} | ||
`) | ||
} | ||
|
||
func testAccDataSourceAwsAvailabilityZoneConfigZoneId() string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "test" {} | ||
data "aws_availability_zone" "test" { | ||
zone_id = data.aws_availability_zones.test.zone_ids[0] | ||
} | ||
`) | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.