GetSubnet

aws.ec2.Subnet provides details about a specific VPC subnet.

This resource can prove useful when a module accepts a subnet id as an input variable and needs to, for example, determine the id of the VPC that the subnet belongs to.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var subnetId = config.RequireObject<dynamic>("subnetId");
        var selected = Output.Create(Aws.Ec2.GetSubnet.InvokeAsync(new Aws.Ec2.GetSubnetArgs
        {
            Id = subnetId,
        }));
        var subnet = new Aws.Ec2.SecurityGroup("subnet", new Aws.Ec2.SecurityGroupArgs
        {
            Ingress = 
            {
                new Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    CidrBlocks = 
                    {
                        selected.Apply(selected => selected.CidrBlock),
                    },
                    FromPort = 80,
                    Protocol = "tcp",
                    ToPort = 80,
                },
            },
            VpcId = selected.Apply(selected => selected.VpcId),
        });
    }

}
package main

import (
    "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 := subnetId
        selected, err := ec2.LookupSubnet(ctx, &ec2.LookupSubnetArgs{
            Id: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        _, err = ec2.NewSecurityGroup(ctx, "subnet", &ec2.SecurityGroupArgs{
            Ingress: ec2.SecurityGroupIngressArray{
                &ec2.SecurityGroupIngressArgs{
                    CidrBlocks: pulumi.StringArray{
                        pulumi.String(selected.CidrBlock),
                    },
                    FromPort: pulumi.Int(80),
                    Protocol: pulumi.String("tcp"),
                    ToPort:   pulumi.Int(80),
                },
            },
            VpcId: pulumi.String(selected.VpcId),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

config = pulumi.Config()
subnet_id = config.require_object("subnetId")
selected = aws.ec2.get_subnet(id=subnet_id)
subnet = aws.ec2.SecurityGroup("subnet",
    ingress=[{
        "cidr_blocks": [selected.cidr_block],
        "from_port": 80,
        "protocol": "tcp",
        "to_port": 80,
    }],
    vpc_id=selected.vpc_id)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const subnetId = config.require("subnetId");

const selected = pulumi.output(aws.ec2.getSubnet({
    id: subnetId,
}, { async: true }));
const subnet = new aws.ec2.SecurityGroup("subnet", {
    ingress: [{
        cidrBlocks: [selected.cidrBlock!],
        fromPort: 80,
        protocol: "tcp",
        toPort: 80,
    }],
    vpcId: selected.vpcId!,
});

Using GetSubnet

function getSubnet(args: GetSubnetArgs, opts?: InvokeOptions): Promise<GetSubnetResult>
function  get_subnet(availability_zone=None, availability_zone_id=None, cidr_block=None, default_for_az=None, filters=None, id=None, ipv6_cidr_block=None, state=None, tags=None, vpc_id=None, opts=None)
func LookupSubnet(ctx *Context, args *LookupSubnetArgs, opts ...InvokeOption) (*LookupSubnetResult, error)

Note: This function is named LookupSubnet in the Go SDK.

public static class GetSubnet {
    public static Task<GetSubnetResult> InvokeAsync(GetSubnetArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

AvailabilityZone string

The availability zone where the subnet must reside.

AvailabilityZoneId string

The ID of the Availability Zone for the subnet.

CidrBlock string

The cidr block of the desired subnet.

DefaultForAz bool

Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.

Filters List<GetSubnetFilterArgs>

Custom filter block as described below.

Id string

The id of the specific subnet to retrieve.

Ipv6CidrBlock string

The Ipv6 cidr block of the desired subnet

State string

The state that the desired subnet must have.

Tags Dictionary<string, string>

A map of tags, each pair of which must exactly match a pair on the desired subnet.

VpcId string

The id of the VPC that the desired subnet belongs to.

AvailabilityZone string

The availability zone where the subnet must reside.

AvailabilityZoneId string

The ID of the Availability Zone for the subnet.

CidrBlock string

The cidr block of the desired subnet.

DefaultForAz bool

Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.

Filters []GetSubnetFilter

Custom filter block as described below.

Id string

The id of the specific subnet to retrieve.

Ipv6CidrBlock string

The Ipv6 cidr block of the desired subnet

State string

The state that the desired subnet must have.

Tags map[string]string

A map of tags, each pair of which must exactly match a pair on the desired subnet.

VpcId string

The id of the VPC that the desired subnet belongs to.

availabilityZone string

The availability zone where the subnet must reside.

availabilityZoneId string

The ID of the Availability Zone for the subnet.

cidrBlock string

The cidr block of the desired subnet.

defaultForAz boolean

Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.

filters GetSubnetFilter[]

Custom filter block as described below.

id string

The id of the specific subnet to retrieve.

ipv6CidrBlock string

The Ipv6 cidr block of the desired subnet

state string

The state that the desired subnet must have.

tags {[key: string]: string}

A map of tags, each pair of which must exactly match a pair on the desired subnet.

vpcId string

The id of the VPC that the desired subnet belongs to.

availability_zone str

The availability zone where the subnet must reside.

availability_zone_id str

The ID of the Availability Zone for the subnet.

cidr_block str

The cidr block of the desired subnet.

default_for_az bool

Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.

filters List[GetSubnetFilter]

Custom filter block as described below.

id str

The id of the specific subnet to retrieve.

ipv6_cidr_block str

The Ipv6 cidr block of the desired subnet

state str

The state that the desired subnet must have.

tags Dict[str, str]

A map of tags, each pair of which must exactly match a pair on the desired subnet.

vpc_id str

The id of the VPC that the desired subnet belongs to.

GetSubnet Result

The following output properties are available:

Arn string

The ARN of the subnet.

AssignIpv6AddressOnCreation bool
AvailabilityZone string
AvailabilityZoneId string
CidrBlock string
DefaultForAz bool
Id string
Ipv6CidrBlock string
Ipv6CidrBlockAssociationId string
MapPublicIpOnLaunch bool
OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

OwnerId string

The ID of the AWS account that owns the subnet.

State string
Tags Dictionary<string, string>
VpcId string
Filters List<GetSubnetFilter>
Arn string

The ARN of the subnet.

AssignIpv6AddressOnCreation bool
AvailabilityZone string
AvailabilityZoneId string
CidrBlock string
DefaultForAz bool
Id string
Ipv6CidrBlock string
Ipv6CidrBlockAssociationId string
MapPublicIpOnLaunch bool
OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

OwnerId string

The ID of the AWS account that owns the subnet.

State string
Tags map[string]string
VpcId string
Filters []GetSubnetFilter
arn string

The ARN of the subnet.

assignIpv6AddressOnCreation boolean
availabilityZone string
availabilityZoneId string
cidrBlock string
defaultForAz boolean
id string
ipv6CidrBlock string
ipv6CidrBlockAssociationId string
mapPublicIpOnLaunch boolean
outpostArn string

The Amazon Resource Name (ARN) of the Outpost.

ownerId string

The ID of the AWS account that owns the subnet.

state string
tags {[key: string]: string}
vpcId string
filters GetSubnetFilter[]
arn str

The ARN of the subnet.

assign_ipv6_address_on_creation bool
availability_zone str
availability_zone_id str
cidr_block str
default_for_az bool
id str
ipv6_cidr_block str
ipv6_cidr_block_association_id str
map_public_ip_on_launch bool
outpost_arn str

The Amazon Resource Name (ARN) of the Outpost.

owner_id str

The ID of the AWS account that owns the subnet.

state str
tags Dict[str, str]
vpc_id str
filters List[GetSubnetFilter]

Supporting Types

GetSubnetFilter

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 field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

Values List<string>

Set of values that are accepted for the given field. A subnet will be selected if any one of the given values matches.

Name string

The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

Values []string

Set of values that are accepted for the given field. A subnet will be selected if any one of the given values matches.

name string

The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

values string[]

Set of values that are accepted for the given field. A subnet will be selected if any one of the given values matches.

name str

The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

values List[str]

Set of values that are accepted for the given field. A subnet will be selected if any one of the given values 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.