aws.getAvailabilityZone
Explore with Pulumi AI
aws.getAvailabilityZone
provides details about a specific availability zone (AZ)
in the current region.
This can be used both to validate an availability zone given in a variable and to split the AZ name into its component parts of an AWS region and an AZ identifier letter. The latter may be useful e.g., for implementing a consistent subnet numbering scheme across several regions by mapping both the region and the subnet letter to network numbers.
This is different from the aws.getAvailabilityZones
(plural) data source,
which provides a list of the available zones.
Example Usage
The following example shows how this data source might be used to derive VPC and subnet CIDR prefixes systematically for an availability zone.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const config = new pulumi.Config();
const regionNumber = config.getObject("regionNumber") || {
"ap-northeast-1": 5,
"eu-central-1": 4,
"us-east-1": 1,
"us-west-1": 2,
"us-west-2": 3,
};
const azNumber = config.getObject("azNumber") || {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6,
};
// Retrieve the AZ where we want to create network resources
// This must be in the region selected on the AWS provider.
const example = aws.getAvailabilityZone({
name: "eu-central-1a",
});
// Create a VPC for the region associated with the AZ
const exampleVpc = new aws.ec2.Vpc("example", {cidrBlock: example.then(example => std.cidrsubnet({
input: "10.0.0.0/8",
newbits: 4,
netnum: regionNumber[example.region],
})).then(invoke => invoke.result)});
// Create a subnet for the AZ within the regional VPC
const exampleSubnet = new aws.ec2.Subnet("example", {
vpcId: exampleVpc.id,
cidrBlock: pulumi.all([exampleVpc.cidrBlock, example]).apply(([cidrBlock, example]) => std.cidrsubnetOutput({
input: cidrBlock,
newbits: 4,
netnum: azNumber[example.nameSuffix],
})).apply(invoke => invoke.result),
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std
config = pulumi.Config()
region_number = config.get_object("regionNumber")
if region_number is None:
region_number = {
"ap-northeast-1": 5,
"eu-central-1": 4,
"us-east-1": 1,
"us-west-1": 2,
"us-west-2": 3,
}
az_number = config.get_object("azNumber")
if az_number is None:
az_number = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
}
# Retrieve the AZ where we want to create network resources
# This must be in the region selected on the AWS provider.
example = aws.get_availability_zone(name="eu-central-1a")
# Create a VPC for the region associated with the AZ
example_vpc = aws.ec2.Vpc("example", cidr_block=std.cidrsubnet(input="10.0.0.0/8",
newbits=4,
netnum=region_number[example.region]).result)
# Create a subnet for the AZ within the regional VPC
example_subnet = aws.ec2.Subnet("example",
vpc_id=example_vpc.id,
cidr_block=example_vpc.cidr_block.apply(lambda cidr_block: std.cidrsubnet_output(input=cidr_block,
newbits=4,
netnum=az_number[example.name_suffix])).apply(lambda invoke: invoke.result))
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-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
cfg := config.New(ctx, "")
regionNumber := map[string]interface{}{
"ap-northeast-1": 5,
"eu-central-1": 4,
"us-east-1": 1,
"us-west-1": 2,
"us-west-2": 3,
}
if param := cfg.GetObject("regionNumber"); param != nil {
regionNumber = param
}
azNumber := map[string]interface{}{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
}
if param := cfg.GetObject("azNumber"); param != nil {
azNumber = param
}
// Retrieve the AZ where we want to create network resources
// This must be in the region selected on the AWS provider.
example, err := aws.GetAvailabilityZone(ctx, &aws.GetAvailabilityZoneArgs{
Name: pulumi.StringRef("eu-central-1a"),
}, nil)
if err != nil {
return err
}
invokeCidrsubnet, err := std.Cidrsubnet(ctx, &std.CidrsubnetArgs{
Input: "10.0.0.0/8",
Newbits: 4,
Netnum: regionNumber[example.Region],
}, nil)
if err != nil {
return err
}
// Create a VPC for the region associated with the AZ
exampleVpc, err := ec2.NewVpc(ctx, "example", &ec2.VpcArgs{
CidrBlock: pulumi.String(invokeCidrsubnet.Result),
})
if err != nil {
return err
}
// Create a subnet for the AZ within the regional VPC
_, err = ec2.NewSubnet(ctx, "example", &ec2.SubnetArgs{
VpcId: exampleVpc.ID(),
CidrBlock: pulumi.String(exampleVpc.CidrBlock.ApplyT(func(cidrBlock string) (std.CidrsubnetResult, error) {
return std.CidrsubnetResult(interface{}(std.CidrsubnetOutput(ctx, std.CidrsubnetOutputArgs{
Input: cidrBlock,
Newbits: 4,
Netnum: pulumi.Int(azNumber[example.NameSuffix]),
}, nil))), nil
}).(std.CidrsubnetResultOutput).ApplyT(func(invoke std.CidrsubnetResult) (*string, error) {
return invoke.Result, nil
}).(pulumi.StringPtrOutput)),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var regionNumber = config.GetObject<dynamic>("regionNumber") ??
{
{ "ap-northeast-1", 5 },
{ "eu-central-1", 4 },
{ "us-east-1", 1 },
{ "us-west-1", 2 },
{ "us-west-2", 3 },
};
var azNumber = config.GetObject<dynamic>("azNumber") ??
{
{ "a", 1 },
{ "b", 2 },
{ "c", 3 },
{ "d", 4 },
{ "e", 5 },
{ "f", 6 },
};
// Retrieve the AZ where we want to create network resources
// This must be in the region selected on the AWS provider.
var example = Aws.GetAvailabilityZone.Invoke(new()
{
Name = "eu-central-1a",
});
// Create a VPC for the region associated with the AZ
var exampleVpc = new Aws.Ec2.Vpc("example", new()
{
CidrBlock = Std.Cidrsubnet.Invoke(new()
{
Input = "10.0.0.0/8",
Newbits = 4,
Netnum = regionNumber[example.Apply(getAvailabilityZoneResult => getAvailabilityZoneResult.Region)],
}).Apply(invoke => invoke.Result),
});
// Create a subnet for the AZ within the regional VPC
var exampleSubnet = new Aws.Ec2.Subnet("example", new()
{
VpcId = exampleVpc.Id,
CidrBlock = Output.Tuple(exampleVpc.CidrBlock, example).Apply(values =>
{
var cidrBlock = values.Item1;
var example = values.Item2;
return Std.Cidrsubnet.Invoke(new()
{
Input = cidrBlock,
Newbits = 4,
Netnum = azNumber[example.Apply(getAvailabilityZoneResult => getAvailabilityZoneResult.NameSuffix)],
});
}).Apply(invoke => invoke.Result),
});
});
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.GetAvailabilityZoneArgs;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
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) {
final var config = ctx.config();
final var regionNumber = config.get("regionNumber").orElse(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference));
final var azNumber = config.get("azNumber").orElse(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference));
// Retrieve the AZ where we want to create network resources
// This must be in the region selected on the AWS provider.
final var example = AwsFunctions.getAvailabilityZone(GetAvailabilityZoneArgs.builder()
.name("eu-central-1a")
.build());
// Create a VPC for the region associated with the AZ
var exampleVpc = new Vpc("exampleVpc", VpcArgs.builder()
.cidrBlock(StdFunctions.cidrsubnet(CidrsubnetArgs.builder()
.input("10.0.0.0/8")
.newbits(4)
.netnum(regionNumber[example.applyValue(getAvailabilityZoneResult -> getAvailabilityZoneResult.region())])
.build()).result())
.build());
// Create a subnet for the AZ within the regional VPC
var exampleSubnet = new Subnet("exampleSubnet", SubnetArgs.builder()
.vpcId(exampleVpc.id())
.cidrBlock(exampleVpc.cidrBlock().applyValue(cidrBlock -> StdFunctions.cidrsubnet()).applyValue(invoke -> invoke.result()))
.build());
}
}
Coming soon!
Using getAvailabilityZone
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 getAvailabilityZone(args: GetAvailabilityZoneArgs, opts?: InvokeOptions): Promise<GetAvailabilityZoneResult>
function getAvailabilityZoneOutput(args: GetAvailabilityZoneOutputArgs, opts?: InvokeOptions): Output<GetAvailabilityZoneResult>
def get_availability_zone(all_availability_zones: Optional[bool] = None,
filters: Optional[Sequence[GetAvailabilityZoneFilter]] = None,
name: Optional[str] = None,
state: Optional[str] = None,
zone_id: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetAvailabilityZoneResult
def get_availability_zone_output(all_availability_zones: Optional[pulumi.Input[bool]] = None,
filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetAvailabilityZoneFilterArgs]]]] = None,
name: Optional[pulumi.Input[str]] = None,
state: Optional[pulumi.Input[str]] = None,
zone_id: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetAvailabilityZoneResult]
func GetAvailabilityZone(ctx *Context, args *GetAvailabilityZoneArgs, opts ...InvokeOption) (*GetAvailabilityZoneResult, error)
func GetAvailabilityZoneOutput(ctx *Context, args *GetAvailabilityZoneOutputArgs, opts ...InvokeOption) GetAvailabilityZoneResultOutput
> Note: This function is named GetAvailabilityZone
in the Go SDK.
public static class GetAvailabilityZone
{
public static Task<GetAvailabilityZoneResult> InvokeAsync(GetAvailabilityZoneArgs args, InvokeOptions? opts = null)
public static Output<GetAvailabilityZoneResult> Invoke(GetAvailabilityZoneInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetAvailabilityZoneResult> getAvailabilityZone(GetAvailabilityZoneArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
function: aws:index/getAvailabilityZone:getAvailabilityZone
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. - Filters
List<Get
Availability Zone Filter> - Configuration block(s) for filtering. Detailed below.
- Name string
- Full name of the availability zone to select.
- State string
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - Zone
Id string - Zone ID of the availability zone to select.
- All
Availability boolZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - Filters
[]Get
Availability Zone Filter - Configuration block(s) for filtering. Detailed below.
- Name string
- Full name of the availability zone to select.
- State string
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - Zone
Id string - Zone ID of the availability zone to select.
- all
Availability BooleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - filters
List<Get
Availability Zone Filter> - Configuration block(s) for filtering. Detailed below.
- name String
- Full name of the availability zone to select.
- state String
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - zone
Id String - Zone ID of the availability zone to select.
- all
Availability booleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - filters
Get
Availability Zone Filter[] - Configuration block(s) for filtering. Detailed below.
- name string
- Full name of the availability zone to select.
- state string
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - zone
Id string - Zone ID of the availability zone to select.
- all_
availability_ boolzones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - filters
Sequence[Get
Availability Zone Filter] - Configuration block(s) for filtering. Detailed below.
- name str
- Full name of the availability zone to select.
- state str
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - zone_
id str - Zone ID of the availability zone to select.
- all
Availability BooleanZones - Set to
true
to include all Availability Zones and Local Zones regardless of your opt in status. - filters List<Property Map>
- Configuration block(s) for filtering. Detailed below.
- name String
- Full name of the availability zone to select.
- state String
- Specific availability zone state to require. May be any of
"available"
,"information"
or"impaired"
. - zone
Id String - Zone ID of the availability zone to select.
getAvailabilityZone Result
The following output properties are available:
- Group
Name string - 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.
- Name string
- Name
Suffix string - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - Network
Border stringGroup - The name of the location from which the address is advertised.
- Opt
In stringStatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - Parent
Zone stringId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- Parent
Zone stringName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- Region string
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- State string
- Zone
Id string - Zone
Type string - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - All
Availability boolZones - Filters
List<Get
Availability Zone Filter>
- Group
Name string - 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.
- Name string
- Name
Suffix string - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - Network
Border stringGroup - The name of the location from which the address is advertised.
- Opt
In stringStatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - Parent
Zone stringId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- Parent
Zone stringName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- Region string
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- State string
- Zone
Id string - Zone
Type string - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - All
Availability boolZones - Filters
[]Get
Availability Zone Filter
- group
Name String - 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.
- name String
- name
Suffix String - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - network
Border StringGroup - The name of the location from which the address is advertised.
- opt
In StringStatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - parent
Zone StringId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- parent
Zone StringName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- region String
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- state String
- zone
Id String - zone
Type String - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - all
Availability BooleanZones - filters
List<Get
Availability Zone Filter>
- group
Name string - 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.
- name string
- name
Suffix string - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - network
Border stringGroup - The name of the location from which the address is advertised.
- opt
In stringStatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - parent
Zone stringId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- parent
Zone stringName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- region string
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- state string
- zone
Id string - zone
Type string - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - all
Availability booleanZones - filters
Get
Availability Zone Filter[]
- group_
name str - 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.
- name str
- name_
suffix str - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - network_
border_ strgroup - The name of the location from which the address is advertised.
- opt_
in_ strstatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - parent_
zone_ strid - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- parent_
zone_ strname - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- region str
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- state str
- zone_
id str - zone_
type str - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - all_
availability_ boolzones - filters
Sequence[Get
Availability Zone Filter]
- group
Name String - 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.
- name String
- name
Suffix String - Part of the AZ name that appears after the region name, uniquely identifying the AZ within its region.
For Availability Zones this is usually a single letter, for example
a
for theus-west-2a
zone. For Local and Wavelength Zones this is a longer string, for examplewl1-sfo-wlz-1
for theus-west-2-wl1-sfo-wlz-1
zone. - network
Border StringGroup - The name of the location from which the address is advertised.
- opt
In StringStatus - For Availability Zones, this always has the value of
opt-in-not-required
. For Local Zones, this is the opt in status. The possible values areopted-in
andnot-opted-in
. - parent
Zone StringId - ID of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- parent
Zone StringName - Name of the zone that handles some of the Local Zone or Wavelength Zone control plane operations, such as API calls.
- region String
- Region where the selected availability zone resides. This is always the region selected on the provider, since this data source searches only within that region.
- state String
- zone
Id String - zone
Type String - Type of zone. Values are
availability-zone
,local-zone
, andwavelength-zone
. - all
Availability BooleanZones - filters List<Property Map>
Supporting Types
GetAvailabilityZoneFilter
- 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.