aws.getAvailabilityZones
Explore with Pulumi AI
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
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Declare the data source
const available = aws.getAvailabilityZones({
state: "available",
});
// e.g., Create subnets in the first two available availability zones
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])});
import pulumi
import pulumi_aws as aws
# Declare the data source
available = aws.get_availability_zones(state="available")
# e.g., Create subnets in the first two available availability zones
primary = aws.ec2.Subnet("primary", availability_zone=available.names[0])
secondary = aws.ec2.Subnet("secondary", availability_zone=available.names[1])
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Declare the data source
available, err := aws.GetAvailabilityZones(ctx, &aws.GetAvailabilityZonesArgs{
State: pulumi.StringRef("available"),
}, nil)
if err != nil {
return err
}
// e.g., Create subnets in the first two available availability zones
_, 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
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
// Declare the data source
var available = Aws.GetAvailabilityZones.Invoke(new()
{
State = "available",
});
// e.g., Create subnets in the first two available availability zones
var primary = new Aws.Ec2.Subnet("primary", new()
{
AvailabilityZone = available.Apply(getAvailabilityZonesResult => getAvailabilityZonesResult.Names[0]),
});
var secondary = new Aws.Ec2.Subnet("secondary", new()
{
AvailabilityZone = available.Apply(getAvailabilityZonesResult => getAvailabilityZonesResult.Names[1]),
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetAvailabilityZonesArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
// Declare the data source
final var available = AwsFunctions.getAvailabilityZones(GetAvailabilityZonesArgs.builder()
.state("available")
.build());
// e.g., Create subnets in the first two available availability zones
var primary = new Subnet("primary", SubnetArgs.builder()
.availabilityZone(available.applyValue(getAvailabilityZonesResult -> getAvailabilityZonesResult.names()[0]))
.build());
var secondary = new Subnet("secondary", SubnetArgs.builder()
.availabilityZone(available.applyValue(getAvailabilityZonesResult -> getAvailabilityZonesResult.names()[1]))
.build());
}
}
resources:
# e.g., Create subnets in the first two available availability zones
primary:
type: aws:ec2:Subnet
properties:
availabilityZone: ${available.names[0]}
secondary:
type: aws:ec2:Subnet
properties:
availabilityZone: ${available.names[1]}
variables:
# Declare the data source
available:
fn::invoke:
Function: aws:getAvailabilityZones
Arguments:
state: available
By Filter
All Local Zones (regardless of opt-in status):
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = aws.getAvailabilityZones({
allAvailabilityZones: true,
filters: [{
name: "opt-in-status",
values: [
"not-opted-in",
"opted-in",
],
}],
});
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",
],
}])
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := aws.GetAvailabilityZones(ctx, &aws.GetAvailabilityZonesArgs{
AllAvailabilityZones: pulumi.BoolRef(true),
Filters: []aws.GetAvailabilityZonesFilter{
{
Name: "opt-in-status",
Values: []string{
"not-opted-in",
"opted-in",
},
},
},
}, nil)
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = Aws.GetAvailabilityZones.Invoke(new()
{
AllAvailabilityZones = true,
Filters = new[]
{
new Aws.Inputs.GetAvailabilityZonesFilterInputArgs
{
Name = "opt-in-status",
Values = new[]
{
"not-opted-in",
"opted-in",
},
},
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetAvailabilityZonesArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var example = AwsFunctions.getAvailabilityZones(GetAvailabilityZonesArgs.builder()
.allAvailabilityZones(true)
.filters(GetAvailabilityZonesFilterArgs.builder()
.name("opt-in-status")
.values(
"not-opted-in",
"opted-in")
.build())
.build());
}
}
variables:
example:
fn::invoke:
Function: aws:getAvailabilityZones
Arguments:
allAvailabilityZones: true
filters:
- name: opt-in-status
values:
- not-opted-in
- opted-in
Only Availability Zones (no Local Zones):
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = aws.getAvailabilityZones({
filters: [{
name: "opt-in-status",
values: ["opt-in-not-required"],
}],
});
import pulumi
import pulumi_aws as aws
example = aws.get_availability_zones(filters=[{
"name": "opt-in-status",
"values": ["opt-in-not-required"],
}])
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := aws.GetAvailabilityZones(ctx, &aws.GetAvailabilityZonesArgs{
Filters: []aws.GetAvailabilityZonesFilter{
{
Name: "opt-in-status",
Values: []string{
"opt-in-not-required",
},
},
},
}, nil)
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = Aws.GetAvailabilityZones.Invoke(new()
{
Filters = new[]
{
new Aws.Inputs.GetAvailabilityZonesFilterInputArgs
{
Name = "opt-in-status",
Values = new[]
{
"opt-in-not-required",
},
},
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetAvailabilityZonesArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var example = AwsFunctions.getAvailabilityZones(GetAvailabilityZonesArgs.builder()
.filters(GetAvailabilityZonesFilterArgs.builder()
.name("opt-in-status")
.values("opt-in-not-required")
.build())
.build());
}
}
variables:
example:
fn::invoke:
Function: aws:getAvailabilityZones
Arguments:
filters:
- name: opt-in-status
values:
- opt-in-not-required
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:
- All
Availability boolZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - Exclude
Names List<string> - List of Availability Zone names to exclude.
- Exclude
Zone List<string>Ids - List of Availability Zone IDs to exclude.
- Filters
List<Get
Availability Zones Filter> - 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 boolZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - Exclude
Names []string - List of Availability Zone names to exclude.
- Exclude
Zone []stringIds - List of Availability Zone IDs to exclude.
- Filters
[]Get
Availability Zones Filter - 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 BooleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - exclude
Names List<String> - List of Availability Zone names to exclude.
- exclude
Zone List<String>Ids - List of Availability Zone IDs to exclude.
- filters
List<Get
Availability Zones Filter> - 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 booleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - exclude
Names string[] - List of Availability Zone names to exclude.
- exclude
Zone string[]Ids - List of Availability Zone IDs to exclude.
- filters
Get
Availability Zones Filter[] - 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_ boolzones - 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_ Sequence[str]ids - List of Availability Zone IDs to exclude.
- filters
Sequence[Get
Availability Zones Filter] - 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.
- all
Availability BooleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - exclude
Names List<String> - List of Availability Zone names to exclude.
- exclude
Zone List<String>Ids - 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:
- Group
Names List<string> - 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
us-west-2-lax-1
. - Id string
- The provider-assigned unique ID for this managed resource.
- Names List<string>
- List of the Availability Zone names available to the account.
- Zone
Ids List<string> - List of the Availability Zone IDs available to the account.
- All
Availability boolZones - Exclude
Names List<string> - Exclude
Zone List<string>Ids - Filters
List<Get
Availability Zones Filter> - State string
- Group
Names []string - 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
us-west-2-lax-1
. - Id string
- The provider-assigned unique ID for this managed resource.
- Names []string
- List of the Availability Zone names available to the account.
- Zone
Ids []string - List of the Availability Zone IDs available to the account.
- All
Availability boolZones - Exclude
Names []string - Exclude
Zone []stringIds - Filters
[]Get
Availability Zones Filter - State string
- group
Names List<String> - 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
us-west-2-lax-1
. - id String
- The provider-assigned unique ID for this managed resource.
- names List<String>
- List of the Availability Zone names available to the account.
- zone
Ids List<String> - List of the Availability Zone IDs available to the account.
- all
Availability BooleanZones - exclude
Names List<String> - exclude
Zone List<String>Ids - filters
List<Get
Availability Zones Filter> - state String
- group
Names string[] - 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
us-west-2-lax-1
. - id string
- The provider-assigned unique ID for this managed resource.
- names string[]
- List of the Availability Zone names available to the account.
- zone
Ids string[] - List of the Availability Zone IDs available to the account.
- all
Availability booleanZones - exclude
Names string[] - exclude
Zone string[]Ids - filters
Get
Availability Zones Filter[] - state string
- group_
names Sequence[str] - 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
us-west-2-lax-1
. - id str
- The provider-assigned unique ID for this managed resource.
- names Sequence[str]
- List of the Availability Zone names available to the account.
- zone_
ids Sequence[str] - List of the Availability Zone IDs available to the account.
- all_
availability_ boolzones - exclude_
names Sequence[str] - exclude_
zone_ Sequence[str]ids - filters
Sequence[Get
Availability Zones Filter] - state str
- group
Names List<String> - 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
us-west-2-lax-1
. - id String
- The provider-assigned unique ID for this managed resource.
- names List<String>
- List of the Availability Zone names available to the account.
- zone
Ids List<String> - List of the Availability Zone IDs available to the account.
- all
Availability BooleanZones - exclude
Names List<String> - exclude
Zone List<String>Ids - filters List<Property Map>
- state String
Supporting Types
GetAvailabilityZonesFilter
- Name string
- 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
- 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
- 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
- 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
- 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
- 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
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.