AWS Classic

Pulumi Official
Package maintained by Pulumi
v5.9.2 published on Friday, Jun 24, 2022 by Pulumi

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/v5/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		available, err := aws.GetAvailabilityZones(ctx, &GetAvailabilityZonesArgs{
			State: pulumi.StringRef("available"),
		}, 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
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var available = Output.of(AwsFunctions.getAvailabilityZones(GetAvailabilityZonesArgs.builder()
            .state("available")
            .build()));

        var primary = new Subnet("primary", SubnetArgs.builder()        
            .availabilityZone(available.apply(getAvailabilityZonesResult -> getAvailabilityZonesResult.names()[0]))
            .build());

        var secondary = new Subnet("secondary", SubnetArgs.builder()        
            .availabilityZone(available.apply(getAvailabilityZonesResult -> getAvailabilityZonesResult.names()[1]))
            .build());

    }
}
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])});
// ...
resources:
  primary:
    type: aws:ec2:Subnet
    properties:
      availabilityZone: ${available.names[0]}
  secondary:
    type: aws:ec2:Subnet
    properties:
      availabilityZone: ${available.names[1]}
variables:
  available:
    Fn::Invoke:
      Function: aws:getAvailabilityZones
      Arguments:
        state: available

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/v5/go/aws"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

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

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var example = Output.of(AwsFunctions.getAvailabilityZones(GetAvailabilityZonesArgs.builder()
            .allAvailabilityZones(true)
            .filters(GetAvailabilityZonesFilterArgs.builder()
                .name("opt-in-status")
                .values(                
                    "not-opted-in",
                    "opted-in")
                .build())
            .build()));

    }
}
import pulumi
import pulumi_aws as aws

example = aws.get_availability_zones(all_availability_zones=True,
    filters=[aws.GetAvailabilityZonesFilterArgs(
        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",
        ],
    }],
}));
variables:
  example:
    Fn::Invoke:
      Function: aws:getAvailabilityZones
      Arguments:
        allAvailabilityZones: true
        filters:
          - name: opt-in-status
            values:
              - not-opted-in
              - opted-in

Using getAvailabilityZones

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getAvailabilityZones(args: GetAvailabilityZonesArgs, opts?: InvokeOptions): Promise<GetAvailabilityZonesResult>
function getAvailabilityZonesOutput(args: GetAvailabilityZonesOutputArgs, opts?: InvokeOptions): Output<GetAvailabilityZonesResult>
def get_availability_zones(all_availability_zones: Optional[bool] = None,
                           exclude_names: Optional[Sequence[str]] = None,
                           exclude_zone_ids: Optional[Sequence[str]] = None,
                           filters: Optional[Sequence[GetAvailabilityZonesFilter]] = None,
                           state: Optional[str] = None,
                           opts: Optional[InvokeOptions] = None) -> GetAvailabilityZonesResult
def get_availability_zones_output(all_availability_zones: Optional[pulumi.Input[bool]] = None,
                           exclude_names: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
                           exclude_zone_ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
                           filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetAvailabilityZonesFilterArgs]]]] = None,
                           state: Optional[pulumi.Input[str]] = None,
                           opts: Optional[InvokeOptions] = None) -> Output[GetAvailabilityZonesResult]
func GetAvailabilityZones(ctx *Context, args *GetAvailabilityZonesArgs, opts ...InvokeOption) (*GetAvailabilityZonesResult, error)
func GetAvailabilityZonesOutput(ctx *Context, args *GetAvailabilityZonesOutputArgs, opts ...InvokeOption) GetAvailabilityZonesResultOutput

> Note: This function is named GetAvailabilityZones in the Go SDK.

public static class GetAvailabilityZones 
{
    public static Task<GetAvailabilityZonesResult> InvokeAsync(GetAvailabilityZonesArgs args, InvokeOptions? opts = null)
    public static Output<GetAvailabilityZonesResult> Invoke(GetAvailabilityZonesInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetAvailabilityZonesResult> getAvailabilityZones(GetAvailabilityZonesArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: aws:index/getAvailabilityZones:getAvailabilityZones
  Arguments:
    # Arguments dictionary

The following arguments are supported:

AllAvailabilityZones bool

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

ExcludeNames List<string>

List of Availability Zone names to exclude.

ExcludeZoneIds List<string>

List of Availability Zone IDs to exclude.

Filters List<GetAvailabilityZonesFilter>

Configuration block(s) for filtering. Detailed below.

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.

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.

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.

excludeNames List<String>

List of Availability Zone names to exclude.

excludeZoneIds List<String>

List of Availability Zone IDs to exclude.

filters List<GetAvailabilityZonesFilter>

Configuration block(s) for filtering. Detailed below.

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.

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.

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.

exclude_names Sequence[str]

List of Availability Zone names to exclude.

exclude_zone_ids Sequence[str]

List of Availability Zone IDs to exclude.

filters Sequence[GetAvailabilityZonesFilter]

Configuration block(s) for filtering. Detailed below.

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.

allAvailabilityZones Boolean

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

excludeNames List<String>

List of Availability Zone names to exclude.

excludeZoneIds List<String>

List of Availability Zone IDs to exclude.

filters List<Property Map>

Configuration block(s) for filtering. Detailed below.

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.

getAvailabilityZones Result

The following output properties are available:

GroupNames List<string>
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
ExcludeNames List<string>
ExcludeZoneIds List<string>
Filters List<GetAvailabilityZonesFilter>
State string
GroupNames []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
ExcludeNames []string
ExcludeZoneIds []string
Filters []GetAvailabilityZonesFilter
State string
groupNames List<String>
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 Boolean
excludeNames List<String>
excludeZoneIds List<String>
filters List<GetAvailabilityZonesFilter>
state String
groupNames 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
excludeNames string[]
excludeZoneIds string[]
filters GetAvailabilityZonesFilter[]
state string
group_names Sequence[str]
id str

The provider-assigned unique ID for this managed resource.

names Sequence[str]

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

zone_ids Sequence[str]

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

all_availability_zones bool
exclude_names Sequence[str]
exclude_zone_ids Sequence[str]
filters Sequence[GetAvailabilityZonesFilter]
state str
groupNames List<String>
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 Boolean
excludeNames List<String>
excludeZoneIds List<String>
filters List<Property Map>
state String

Supporting Types

GetAvailabilityZonesFilter

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 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 str

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

values Sequence[str]

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 List<String>

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.