Skip to content

Data Source: awsAvailabilityZones

The Availability Zones data source allows access to the list of AWS Availability Zones which can be accessed by an AWS account within the region configured in the provider.

This is different from the awsAvailabilityZone (singular) data source, which provides some details about a specific availability zone.

-> When Local Zones are enabled in a region, by default the API and this data source include both Local Zones and Availability Zones. To return only Availability Zones, see the example section below.

Example Usage

By State

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsAvailabilityZonesAvailable =
  new aws.dataAwsAvailabilityZones.DataAwsAvailabilityZones(this, "available", {
    state: "available",
  });
new aws.subnet.Subnet(this, "primary", {
  availabilityZone: `\${${dataAwsAvailabilityZonesAvailable.names.fqn}[0]}`,
});
new aws.subnet.Subnet(this, "secondary", {
  availabilityZone: `\${${dataAwsAvailabilityZonesAvailable.names.fqn}[1]}`,
});

By Filter

All Local Zones (regardless of opt-in status):

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dataAwsAvailabilityZones.DataAwsAvailabilityZones(this, "example", {
  allAvailabilityZones: true,
  filter: [
    {
      name: "opt-in-status",
      values: ["not-opted-in", "opted-in"],
    },
  ],
});

Only Availability Zones (no Local Zones):

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dataAwsAvailabilityZones.DataAwsAvailabilityZones(this, "example", {
  filter: [
    {
      name: "opt-in-status",
      values: ["opt-in-not-required"],
    },
  ],
});

Argument Reference

The following arguments are supported:

  • 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.
  • excludeNames - (Optional) List of Availability Zone names to exclude.
  • excludeZoneIds - (Optional) List of Availability Zone IDs to exclude.
  • state - (Optional) Allows to filter list of Availability Zones based on their current state. Can be either "available", "information", "impaired" or "unavailable". By default the list includes a complete set of Availability Zones to which the underlying AWS account has access, regardless of their state.

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:

  • groupNames A set of the Availability Zone Group names. For Availability Zones, this is the same value as the Region name. For Local Zones, the name of the associated group, for example usWest2Lax1.
  • id - Region of the Availability Zones.
  • names - List of the Availability Zone names available to the account.
  • zoneIds - List of the Availability Zone IDs available to the account.

Note that the indexes of Availability Zone names and IDs correspond.

Timeouts

Configuration options:

  • read - (Default 20M)