Skip to content

Data Source: awsAvailabilityZone

awsAvailabilityZone provides details about a specific availability zone (AZ) in the current region.

This can be used both to validate an availability zone given in a variable and to split the AZ name into its component parts of an AWS region and an AZ identifier letter. The latter may be useful e.g., for implementing a consistent subnet numbering scheme across several regions by mapping both the region and the subnet letter to network numbers.

This is different from the awsAvailabilityZones (plural) data source, which provides a list of the available zones.

Example Usage

The following example shows how this data source might be used to derive VPC and subnet CIDR prefixes systematically for an availability zone.

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
You can read more about this at https://cdk.tf/variables*/
const azNumber = new cdktf.TerraformVariable(this, "az_number", {
  default: [
    {
      a: 1,
      b: 2,
      c: 3,
      d: 4,
      e: 5,
      f: 6,
    },
  ],
});
const regionNumber = new cdktf.TerraformVariable(this, "region_number", {
  default: [
    {
      "ap-northeast-1": 5,
      "eu-central-1": 4,
      "us-east-1": 1,
      "us-west-1": 2,
      "us-west-2": 3,
    },
  ],
});
const dataAwsAvailabilityZoneExample =
  new aws.dataAwsAvailabilityZone.DataAwsAvailabilityZone(this, "example", {
    name: "eu-central-1a",
  });
const awsVpcExample = new aws.vpc.Vpc(this, "example_3", {
  cidrBlock: `\${cidrsubnet("10.0.0.0/8", 4, ${regionNumber.value}[${dataAwsAvailabilityZoneExample.region}])}`,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsVpcExample.overrideLogicalId("example");
const awsSubnetExample = new aws.subnet.Subnet(this, "example_4", {
  cidrBlock: `\${cidrsubnet(${awsVpcExample.cidrBlock}, 4, ${azNumber.value}[${dataAwsAvailabilityZoneExample.nameSuffix}])}`,
  vpcId: awsVpcExample.id,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsSubnetExample.overrideLogicalId("example");

Argument Reference

The arguments of this data source act as filters for querying the available availability zones. The given filters must match exactly one availability zone whose data will be exported as attributes.

  • allAvailabilityZones - (Optional) Set to true to include all Availability Zones and Local Zones regardless of your opt in status.
  • filter - (Optional) Configuration block(s) for filtering. Detailed below.
  • name - (Optional) Full name of the availability zone to select.
  • state - (Optional) Specific availability zone state to require. May be any of "available", "information" or "impaired".
  • zoneId - (Optional) Zone ID of the availability zone to select.

filter Configuration Block

The following arguments are supported by the filter configuration block:

  • name - (Required) Name of the filter field. Valid values can be found in the EC2 DescribeAvailabilityZones API Reference.
  • values - (Required) Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • groupName - For Availability Zones, this is the same value as the Region name. For Local Zones, the name of the associated group, for example usWest2Lax1.
  • nameSuffix - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region. For Availability Zones this is usually a single letter, for example a for the usWest2A zone. For Local and Wavelength Zones this is a longer string, for example wl1SfoWlz1 for the usWest2Wl1SfoWlz1 zone.
  • networkBorderGroup - The name of the location from which the address is advertised.
  • optInStatus - For Availability Zones, this always has the value of optInNotRequired. For Local Zones, this is the opt in status. The possible values are optedIn and notOptedIn.
  • parentZoneId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
  • parentZoneName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
  • region - Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
  • zoneType - Type of zone. Values are availabilityZone, localZone, and wavelengthZone.

Timeouts

Configuration options:

  • read - (Default 20M)