数据可用性区域跳过 AZ

Data availability zones skipping AZ

我正在尝试在 AWS 中为每个区域的每个 AZ 创建子网。我能够阅读 aws_availability_zones data source 但是当我遍历列表时它 returns us-west-1aus-west-1c (不存在)。

data "aws_availability_zones" "available" {}

resource "aws_subnet" "example" {
  count = length(data.aws_availability_zones.all.names)

  vpc_id                  = aws_vpc.main.id
  cidr_block              = cidrsubnet(var.cidr, 8, count.index)
  availability_zone       = element(data.aws_availability_zones.all.names, count.index)
  map_public_ip_on_launch = true
}

我希望它 return us-west-1aus-west-1b

它目前 returns us-west-1aus-west-1c

可用区名称是 randomised:

To ensure that resources are distributed across the Availability Zones for a Region, we independently map Availability Zones to names for each account. For example, the Availability Zone us-east-1a for your AWS account might not have the same location as us-east-1a for another AWS account. For more information, see Regions and Availability Zones in the Amazon EC2 User Guide.

To identify the location of your resources relative to your accounts, you must use the AZ ID, which is a unique and consistent identifier for an Availability Zone. For example, use1-az1 is an AZ ID for the us-east-1 Region and it is the same location in every AWS account.

us-west-1 是一个有点奇怪的区域,它有 2 个可用区域:usw1-az1usw1-az3,这些区域是随机分配的 abc 每个帐户。

aws ec2 describe-availability-zones --region us-west-1
{
    "AvailabilityZones": [
        {
            "State": "available", 
            "ZoneName": "us-west-1a", 
            "Messages": [], 
            "ZoneId": "usw1-az3", 
            "RegionName": "us-west-1"
        }, 
        {
            "State": "available", 
            "ZoneName": "us-west-1b", 
            "Messages": [], 
            "ZoneId": "usw1-az1", 
            "RegionName": "us-west-1"
        }
    ]
}

运行 来自另一个 AWS 账户:

aws ec2 describe-availability-zones --region us-west-1
{
    "AvailabilityZones": [
        {
            "State": "available", 
            "ZoneName": "us-west-1b", 
            "Messages": [], 
            "ZoneId": "usw1-az3", 
            "RegionName": "us-west-1"
        }, 
        {
            "State": "available", 
            "ZoneName": "us-west-1c", 
            "Messages": [], 
            "ZoneId": "usw1-az1", 
            "RegionName": "us-west-1"
        }
    ]
}

我不知道 usw1-az2 发生了什么,但它不再是一个有效的 AZ 并且查看 old gist of mine 它已经很久没有了。