github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/d/availability_zone.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_availability_zone" 4 sidebar_current: "docs-aws-datasource-availability-zone" 5 description: |- 6 Provides details about a specific availability zone 7 --- 8 9 # aws\_availability\_zone 10 11 `aws_availability_zone` provides details about a specific availability zone (AZ) 12 in the current region. 13 14 This can be used both to validate an availability zone given in a variable 15 and to split the AZ name into its component parts of an AWS region and an 16 AZ identifier letter. The latter may be useful e.g. for implementing a 17 consistent subnet numbering scheme across several regions by mapping both 18 the region and the subnet letter to network numbers. 19 20 This is different from the `aws_availability_zones` (plural) data source, 21 which provides a list of the available zones. 22 23 ## Example Usage 24 25 The following example shows how this data source might be used to derive 26 VPC and subnet CIDR prefixes systematically for an availability zone. 27 28 ``` 29 variable "region_number" { 30 # Arbitrary mapping of region name to number to use in 31 # a VPC's CIDR prefix. 32 default = { 33 us-east-1 = 1 34 us-west-1 = 2 35 us-west-2 = 3 36 eu-central-1 = 4 37 ap-northeast-1 = 5 38 } 39 } 40 41 variable "az_number" { 42 # Assign a number to each AZ letter used in our configuration 43 default = { 44 a = 1 45 b = 2 46 c = 3 47 d = 4 48 e = 5 49 f = 6 50 } 51 } 52 53 # Retrieve the AZ where we want to create network resources 54 # This must be in the region selected on the AWS provider. 55 data "aws_availability_zone" "example" { 56 name = "eu-central-1a" 57 } 58 59 # Create a VPC for the region associated with the AZ 60 resource "aws_vpc" "example" { 61 cidr_block = "${cidrsubnet("10.0.0.0/8", 4, var.region_number[data.aws_availability_zone.example.region])}" 62 } 63 64 # Create a subnet for the AZ within the regional VPC 65 resource "aws_subnet" "example" { 66 vpc_id = "${aws_vpc.example.id}" 67 cidr_block = "${cidrsubnet(aws_vpc.example.cidr_block, 4, var.az_number[data.aws_availability_zone.example.name_suffix])}" 68 } 69 ``` 70 71 ## Argument Reference 72 73 The arguments of this data source act as filters for querying the available 74 availability zones. The given filters must match exactly one availability 75 zone whose data will be exported as attributes. 76 77 * `name` - (Optional) The full name of the availability zone to select. 78 79 * `state` - (Optional) A specific availability zone state to require. May 80 be any of `"available"`, `"information"`, `"impaired"` or `"available"`. 81 82 All reasonable uses of this data source will specify `name`, since `state` 83 alone would match a single AZ only in a region that itself has only one AZ. 84 85 ## Attributes Reference 86 87 The following attributes are exported: 88 89 * `name` - The name of the selected availability zone. 90 91 * `region` - The region where the selected availability zone resides. 92 This is always the region selected on the provider, since this data source 93 searches only within that region. 94 95 * `name_suffix` - The part of the AZ name that appears after the region name, 96 uniquely identifying the AZ within its region. 97 98 * `state` - The current state of the AZ.