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
LookupSubnetin the Go SDK.
public static class GetSubnet {
public static Task<GetSubnetResult> InvokeAsync(GetSubnetArgs args, InvokeOptions? opts = null)
}The following arguments are supported:
- Availability
Zone string The availability zone where the subnet must reside.
- Availability
Zone stringId The ID of the Availability Zone for the subnet.
- Cidr
Block string The cidr block of the desired subnet.
- Default
For boolAz Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.
- Filters
List<Get
Subnet Filter Args> Custom filter block as described below.
- Id string
The id of the specific subnet to retrieve.
- Ipv6Cidr
Block string The Ipv6 cidr block of the desired subnet
- State string
The state that the desired subnet must have.
- Dictionary<string, string>
A map of tags, each pair of which must exactly match a pair on the desired subnet.
- Vpc
Id string The id of the VPC that the desired subnet belongs to.
- Availability
Zone string The availability zone where the subnet must reside.
- Availability
Zone stringId The ID of the Availability Zone for the subnet.
- Cidr
Block string The cidr block of the desired subnet.
- Default
For boolAz Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.
- Filters
[]Get
Subnet Filter Custom filter block as described below.
- Id string
The id of the specific subnet to retrieve.
- Ipv6Cidr
Block string The Ipv6 cidr block of the desired subnet
- State string
The state that the desired subnet must have.
- map[string]string
A map of tags, each pair of which must exactly match a pair on the desired subnet.
- Vpc
Id string The id of the VPC that the desired subnet belongs to.
- availability
Zone string The availability zone where the subnet must reside.
- availability
Zone stringId The ID of the Availability Zone for the subnet.
- cidr
Block string The cidr block of the desired subnet.
- default
For booleanAz Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.
- filters
Get
Subnet Filter[] Custom filter block as described below.
- id string
The id of the specific subnet to retrieve.
- ipv6Cidr
Block string The Ipv6 cidr block of the desired subnet
- state string
The state that the desired subnet must have.
- {[key: string]: string}
A map of tags, each pair of which must exactly match a pair on the desired subnet.
- vpc
Id 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_ strid The ID of the Availability Zone for the subnet.
- cidr_
block str The cidr block of the desired subnet.
- default_
for_ boolaz Boolean constraint for whether the desired subnet must be the default subnet for its associated availability zone.
- filters
List[Get
Subnet Filter] Custom filter block as described below.
- id str
The id of the specific subnet to retrieve.
- ipv6_
cidr_ strblock The Ipv6 cidr block of the desired subnet
- state str
The state that the desired subnet must have.
- 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.
- Assign
Ipv6Address boolOn Creation - Availability
Zone string - Availability
Zone stringId - Cidr
Block string - Default
For boolAz - Id string
- Ipv6Cidr
Block string - Ipv6Cidr
Block stringAssociation Id - Map
Public boolIp On Launch - Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Owner
Id string The ID of the AWS account that owns the subnet.
- State string
- Dictionary<string, string>
- Vpc
Id string - Filters
List<Get
Subnet Filter>
- Arn string
The ARN of the subnet.
- Assign
Ipv6Address boolOn Creation - Availability
Zone string - Availability
Zone stringId - Cidr
Block string - Default
For boolAz - Id string
- Ipv6Cidr
Block string - Ipv6Cidr
Block stringAssociation Id - Map
Public boolIp On Launch - Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Owner
Id string The ID of the AWS account that owns the subnet.
- State string
- map[string]string
- Vpc
Id string - Filters
[]Get
Subnet Filter
- arn string
The ARN of the subnet.
- assign
Ipv6Address booleanOn Creation - availability
Zone string - availability
Zone stringId - cidr
Block string - default
For booleanAz - id string
- ipv6Cidr
Block string - ipv6Cidr
Block stringAssociation Id - map
Public booleanIp On Launch - outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- owner
Id string The ID of the AWS account that owns the subnet.
- state string
- {[key: string]: string}
- vpc
Id string - filters
Get
Subnet Filter[]
- arn str
The ARN of the subnet.
- assign_
ipv6_ booladdress_ on_ creation - availability_
zone str - availability_
zone_ strid - cidr_
block str - default_
for_ boolaz - id str
- ipv6_
cidr_ strblock - ipv6_
cidr_ strblock_ association_ id - map_
public_ boolip_ on_ launch - 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
- Dict[str, str]
- vpc_
id str - filters
List[Get
Subnet Filter]
Supporting Types
GetSubnetFilter
- 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
awsTerraform Provider.