1. Packages
  2. AWS
  3. API Docs
  4. getAvailabilityZones
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

aws.getAvailabilityZones

Explore with Pulumi AI

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

    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:

    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>
    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.
    ZoneIds List<string>
    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
    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.
    ZoneIds []string
    List of the Availability Zone IDs available to the account.
    AllAvailabilityZones bool
    ExcludeNames []string
    ExcludeZoneIds []string
    Filters []GetAvailabilityZonesFilter
    State string
    groupNames 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.
    zoneIds List<String>
    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[]
    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.
    zoneIds string[]
    List of the Availability Zone IDs available to the account.
    allAvailabilityZones boolean
    excludeNames string[]
    excludeZoneIds string[]
    filters GetAvailabilityZonesFilter[]
    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_zones bool
    exclude_names Sequence[str]
    exclude_zone_ids Sequence[str]
    filters Sequence[GetAvailabilityZonesFilter]
    state str
    groupNames 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.
    zoneIds List<String>
    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
    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.
    aws logo
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi