GetAvailabilityZones

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 aws.getAvailabilityZone (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

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var available = Output.Create(Aws.GetAvailabilityZones.InvokeAsync(new Aws.GetAvailabilityZonesArgs
        {
            State = "available",
        }));
        var primary = new Aws.Ec2.Subnet("primary", new Aws.Ec2.SubnetArgs
        {
            AvailabilityZone = available.Apply(available => available.Names[0]),
        });
        // ...
        var secondary = new Aws.Ec2.Subnet("secondary", new Aws.Ec2.SubnetArgs
        {
            AvailabilityZone = available.Apply(available => available.Names[1]),
        });
        // ...
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        opt0 := "available"
        available, err := aws.GetAvailabilityZones(ctx, &aws.GetAvailabilityZonesArgs{
            State: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        _, err = ec2.NewSubnet(ctx, "primary", &ec2.SubnetArgs{
            AvailabilityZone: pulumi.String(available.Names[0]),
        })
        if err != nil {
            return err
        }
        _, err = ec2.NewSubnet(ctx, "secondary", &ec2.SubnetArgs{
            AvailabilityZone: pulumi.String(available.Names[1]),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

available = aws.get_availability_zones(state="available")
primary = aws.ec2.Subnet("primary", availability_zone=available.names[0])
# ...
secondary = aws.ec2.Subnet("secondary", availability_zone=available.names[1])
# ...
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const available = aws.getAvailabilityZones({
    state: "available",
});
const primary = new aws.ec2.Subnet("primary", {availabilityZone: available.then(available => available.names[0])});
// ...
const secondary = new aws.ec2.Subnet("secondary", {availabilityZone: available.then(available => available.names[1])});
// ...

By Filter

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var example = Output.Create(Aws.GetAvailabilityZones.InvokeAsync(new Aws.GetAvailabilityZonesArgs
        {
            AllAvailabilityZones = true,
            Filters = 
            {
                new Aws.Inputs.GetAvailabilityZonesFilterArgs
                {
                    Name = "opt-in-status",
                    Values = 
                    {
                        "not-opted-in",
                        "opted-in",
                    },
                },
            },
        }));
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        opt0 := true
        _, err := aws.GetAvailabilityZones(ctx, &aws.GetAvailabilityZonesArgs{
            AllAvailabilityZones: &opt0,
            Filters: []aws.GetAvailabilityZonesFilter{
                aws.GetAvailabilityZonesFilter{
                    Name: "opt-in-status",
                    Values: []string{
                        "not-opted-in",
                        "opted-in",
                    },
                },
            },
        }, nil)
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

example = aws.get_availability_zones(all_availability_zones=True,
    filters=[{
        "name": "opt-in-status",
        "values": [
            "not-opted-in",
            "opted-in",
        ],
    }])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = pulumi.output(aws.getAvailabilityZones({
    allAvailabilityZones: true,
    filters: [{
        name: "opt-in-status",
        values: [
            "not-opted-in",
            "opted-in",
        ],
    }],
}, { async: true }));

Using GetAvailabilityZones

function getAvailabilityZones(args: GetAvailabilityZonesArgs, opts?: InvokeOptions): Promise<GetAvailabilityZonesResult>
function  get_availability_zones(all_availability_zones=None, blacklisted_names=None, blacklisted_zone_ids=None, exclude_names=None, exclude_zone_ids=None, filters=None, group_names=None, state=None, opts=None)
func GetAvailabilityZones(ctx *Context, args *GetAvailabilityZonesArgs, opts ...InvokeOption) (*GetAvailabilityZonesResult, error)
public static class GetAvailabilityZones {
    public static Task<GetAvailabilityZonesResult> InvokeAsync(GetAvailabilityZonesArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

AllAvailabilityZones bool

Set to true to include all Availability Zones and Local Zones regardless of your opt in status.

BlacklistedNames List<string>

List of Availability Zone names to exclude. Use exclude_names instead.

Deprecated: use exclude_names instead

BlacklistedZoneIds List<string>

List of Availability Zone IDs to exclude. Use exclude_zone_ids instead.

Deprecated: use exclude_zone_ids instead

ExcludeNames List<string>

List of Availability Zone names to exclude.

ExcludeZoneIds List<string>

List of Availability Zone IDs to exclude.

Filters List<GetAvailabilityZonesFilterArgs>

Configuration block(s) for filtering. Detailed below.

GroupNames List<string>
State string

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.

AllAvailabilityZones bool

Set to true to include all Availability Zones and Local Zones regardless of your opt in status.

BlacklistedNames []string

List of Availability Zone names to exclude. Use exclude_names instead.

Deprecated: use exclude_names instead

BlacklistedZoneIds []string

List of Availability Zone IDs to exclude. Use exclude_zone_ids instead.

Deprecated: use exclude_zone_ids instead

ExcludeNames []string

List of Availability Zone names to exclude.

ExcludeZoneIds []string

List of Availability Zone IDs to exclude.

Filters []GetAvailabilityZonesFilter

Configuration block(s) for filtering. Detailed below.

GroupNames []string
State string

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.

allAvailabilityZones boolean

Set to true to include all Availability Zones and Local Zones regardless of your opt in status.

blacklistedNames string[]

List of Availability Zone names to exclude. Use exclude_names instead.

Deprecated: use exclude_names instead

blacklistedZoneIds string[]

List of Availability Zone IDs to exclude. Use exclude_zone_ids instead.

Deprecated: use exclude_zone_ids instead

excludeNames string[]

List of Availability Zone names to exclude.

excludeZoneIds string[]

List of Availability Zone IDs to exclude.

filters GetAvailabilityZonesFilter[]

Configuration block(s) for filtering. Detailed below.

groupNames string[]
state string

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.

all_availability_zones bool

Set to true to include all Availability Zones and Local Zones regardless of your opt in status.

blacklisted_names List[str]

List of Availability Zone names to exclude. Use exclude_names instead.

Deprecated: use exclude_names instead

blacklisted_zone_ids List[str]

List of Availability Zone IDs to exclude. Use exclude_zone_ids instead.

Deprecated: use exclude_zone_ids instead

exclude_names List[str]

List of Availability Zone names to exclude.

exclude_zone_ids List[str]

List of Availability Zone IDs to exclude.

filters List[GetAvailabilityZonesFilter]

Configuration block(s) for filtering. Detailed below.

group_names List[str]
state str

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.

GetAvailabilityZones Result

The following output properties are available:

Id string

The provider-assigned unique ID for this managed resource.

Names List<string>

A list of the Availability Zone names available to the account.

ZoneIds List<string>

A list of the Availability Zone IDs available to the account.

AllAvailabilityZones bool
BlacklistedNames List<string>

Deprecated: use exclude_names instead

BlacklistedZoneIds List<string>

Deprecated: use exclude_zone_ids instead

ExcludeNames List<string>
ExcludeZoneIds List<string>
Filters List<GetAvailabilityZonesFilter>
GroupNames List<string>
State string
Id string

The provider-assigned unique ID for this managed resource.

Names []string

A list of the Availability Zone names available to the account.

ZoneIds []string

A list of the Availability Zone IDs available to the account.

AllAvailabilityZones bool
BlacklistedNames []string

Deprecated: use exclude_names instead

BlacklistedZoneIds []string

Deprecated: use exclude_zone_ids instead

ExcludeNames []string
ExcludeZoneIds []string
Filters []GetAvailabilityZonesFilter
GroupNames []string
State string
id string

The provider-assigned unique ID for this managed resource.

names string[]

A list of the Availability Zone names available to the account.

zoneIds string[]

A list of the Availability Zone IDs available to the account.

allAvailabilityZones boolean
blacklistedNames string[]

Deprecated: use exclude_names instead

blacklistedZoneIds string[]

Deprecated: use exclude_zone_ids instead

excludeNames string[]
excludeZoneIds string[]
filters GetAvailabilityZonesFilter[]
groupNames string[]
state string
id str

The provider-assigned unique ID for this managed resource.

names List[str]

A list of the Availability Zone names available to the account.

zone_ids List[str]

A list of the Availability Zone IDs available to the account.

all_availability_zones bool
blacklisted_names List[str]

Deprecated: use exclude_names instead

blacklisted_zone_ids List[str]

Deprecated: use exclude_zone_ids instead

exclude_names List[str]
exclude_zone_ids List[str]
filters List[GetAvailabilityZonesFilter]
group_names List[str]
state str

Supporting Types

GetAvailabilityZonesFilter

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Name string

The name of the filter field. Valid values can be found in the EC2 DescribeAvailabilityZones API Reference.

Values List<string>

Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

Name string

The name of the filter field. Valid values can be found in the EC2 DescribeAvailabilityZones API Reference.

Values []string

Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

name string

The name of the filter field. Valid values can be found in the EC2 DescribeAvailabilityZones API Reference.

values string[]

Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

name str

The name of the filter field. Valid values can be found in the EC2 DescribeAvailabilityZones API Reference.

values List[str]

Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.