Subnet
Provides an VPC subnet resource.
NOTE: Due to AWS Lambda improved VPC networking changes that began deploying in September 2019, subnets associated with Lambda Functions can take up to 45 minutes to successfully delete.
Example Usage
Basic Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var main = new Aws.Ec2.Subnet("main", new Aws.Ec2.SubnetArgs
{
CidrBlock = "10.0.1.0/24",
Tags =
{
{ "Name", "Main" },
},
VpcId = aws_vpc.Main.Id,
});
}
}
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 {
_, err := ec2.NewSubnet(ctx, "main", &ec2.SubnetArgs{
CidrBlock: pulumi.String("10.0.1.0/24"),
Tags: pulumi.StringMap{
"Name": pulumi.String("Main"),
},
VpcId: pulumi.String(aws_vpc.Main.Id),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
main = aws.ec2.Subnet("main",
cidr_block="10.0.1.0/24",
tags={
"Name": "Main",
},
vpc_id=aws_vpc["main"]["id"])import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const main = new aws.ec2.Subnet("main", {
cidrBlock: "10.0.1.0/24",
tags: {
Name: "Main",
},
vpcId: aws_vpc_main.id,
});Subnets In Secondary VPC CIDR Blocks
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var secondaryCidr = new Aws.Ec2.VpcIpv4CidrBlockAssociation("secondaryCidr", new Aws.Ec2.VpcIpv4CidrBlockAssociationArgs
{
CidrBlock = "172.2.0.0/16",
VpcId = aws_vpc.Main.Id,
});
var inSecondaryCidr = new Aws.Ec2.Subnet("inSecondaryCidr", new Aws.Ec2.SubnetArgs
{
CidrBlock = "172.2.0.0/24",
VpcId = secondaryCidr.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 {
secondaryCidr, err := ec2.NewVpcIpv4CidrBlockAssociation(ctx, "secondaryCidr", &ec2.VpcIpv4CidrBlockAssociationArgs{
CidrBlock: pulumi.String("172.2.0.0/16"),
VpcId: pulumi.String(aws_vpc.Main.Id),
})
if err != nil {
return err
}
_, err = ec2.NewSubnet(ctx, "inSecondaryCidr", &ec2.SubnetArgs{
CidrBlock: pulumi.String("172.2.0.0/24"),
VpcId: secondaryCidr.VpcId,
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
secondary_cidr = aws.ec2.VpcIpv4CidrBlockAssociation("secondaryCidr",
cidr_block="172.2.0.0/16",
vpc_id=aws_vpc["main"]["id"])
in_secondary_cidr = aws.ec2.Subnet("inSecondaryCidr",
cidr_block="172.2.0.0/24",
vpc_id=secondary_cidr.vpc_id)import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const secondaryCidr = new aws.ec2.VpcIpv4CidrBlockAssociation("secondary_cidr", {
cidrBlock: "172.2.0.0/16",
vpcId: aws_vpc_main.id,
});
const inSecondaryCidr = new aws.ec2.Subnet("in_secondary_cidr", {
cidrBlock: "172.2.0.0/24",
vpcId: secondaryCidr.vpcId,
});Create a Subnet Resource
new Subnet(name: string, args: SubnetArgs, opts?: CustomResourceOptions);def Subnet(resource_name, opts=None, assign_ipv6_address_on_creation=None, availability_zone=None, availability_zone_id=None, cidr_block=None, ipv6_cidr_block=None, map_public_ip_on_launch=None, outpost_arn=None, tags=None, vpc_id=None, __props__=None);func NewSubnet(ctx *Context, name string, args SubnetArgs, opts ...ResourceOption) (*Subnet, error)public Subnet(string name, SubnetArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args SubnetArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args SubnetArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args SubnetArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
Subnet Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The Subnet resource accepts the following input properties:
- Cidr
Block string The CIDR block for the subnet.
- Vpc
Id string The VPC ID.
- Assign
Ipv6Address boolOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- Availability
Zone string The AZ for the subnet.
- Availability
Zone stringId The AZ ID of the subnet.
- Ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- Map
Public boolIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Dictionary<string, string>
A map of tags to assign to the resource.
- Cidr
Block string The CIDR block for the subnet.
- Vpc
Id string The VPC ID.
- Assign
Ipv6Address boolOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- Availability
Zone string The AZ for the subnet.
- Availability
Zone stringId The AZ ID of the subnet.
- Ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- Map
Public boolIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- map[string]string
A map of tags to assign to the resource.
- cidr
Block string The CIDR block for the subnet.
- vpc
Id string The VPC ID.
- assign
Ipv6Address booleanOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- availability
Zone string The AZ for the subnet.
- availability
Zone stringId The AZ ID of the subnet.
- ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- map
Public booleanIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- {[key: string]: string}
A map of tags to assign to the resource.
- cidr_
block str The CIDR block for the subnet.
- vpc_
id str The VPC ID.
- assign_
ipv6_ booladdress_ on_ creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- availability_
zone str The AZ for the subnet.
- availability_
zone_ strid The AZ ID of the subnet.
- ipv6_
cidr_ strblock The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- map_
public_ boolip_ on_ launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- outpost_
arn str The Amazon Resource Name (ARN) of the Outpost.
- Dict[str, str]
A map of tags to assign to the resource.
Outputs
All input properties are implicitly available as output properties. Additionally, the Subnet resource produces the following output properties:
Look up an Existing Subnet Resource
Get an existing Subnet resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: SubnetState, opts?: CustomResourceOptions): Subnetstatic get(resource_name, id, opts=None, arn=None, assign_ipv6_address_on_creation=None, availability_zone=None, availability_zone_id=None, cidr_block=None, ipv6_cidr_block=None, ipv6_cidr_block_association_id=None, map_public_ip_on_launch=None, outpost_arn=None, owner_id=None, tags=None, vpc_id=None, __props__=None);func GetSubnet(ctx *Context, name string, id IDInput, state *SubnetState, opts ...ResourceOption) (*Subnet, error)public static Subnet Get(string name, Input<string> id, SubnetState? state, CustomResourceOptions? opts = null)- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
The following state arguments are supported:
- Arn string
The ARN of the subnet.
- Assign
Ipv6Address boolOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- Availability
Zone string The AZ for the subnet.
- Availability
Zone stringId The AZ ID of the subnet.
- Cidr
Block string The CIDR block for the subnet.
- Ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- Ipv6Cidr
Block stringAssociation Id The association ID for the IPv6 CIDR block.
- Map
Public boolIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Owner
Id string The ID of the AWS account that owns the subnet.
- Dictionary<string, string>
A map of tags to assign to the resource.
- Vpc
Id string The VPC ID.
- Arn string
The ARN of the subnet.
- Assign
Ipv6Address boolOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- Availability
Zone string The AZ for the subnet.
- Availability
Zone stringId The AZ ID of the subnet.
- Cidr
Block string The CIDR block for the subnet.
- Ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- Ipv6Cidr
Block stringAssociation Id The association ID for the IPv6 CIDR block.
- Map
Public boolIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Owner
Id string The ID of the AWS account that owns the subnet.
- map[string]string
A map of tags to assign to the resource.
- Vpc
Id string The VPC ID.
- arn string
The ARN of the subnet.
- assign
Ipv6Address booleanOn Creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- availability
Zone string The AZ for the subnet.
- availability
Zone stringId The AZ ID of the subnet.
- cidr
Block string The CIDR block for the subnet.
- ipv6Cidr
Block string The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- ipv6Cidr
Block stringAssociation Id The association ID for the IPv6 CIDR block.
- map
Public booleanIp On Launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- owner
Id string The ID of the AWS account that owns the subnet.
- {[key: string]: string}
A map of tags to assign to the resource.
- vpc
Id string The VPC ID.
- arn str
The ARN of the subnet.
- assign_
ipv6_ booladdress_ on_ creation Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is
false- availability_
zone str The AZ for the subnet.
- availability_
zone_ strid The AZ ID of the subnet.
- cidr_
block str The CIDR block for the subnet.
- ipv6_
cidr_ strblock The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.
- ipv6_
cidr_ strblock_ association_ id The association ID for the IPv6 CIDR block.
- map_
public_ boolip_ on_ launch Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is
false.- outpost_
arn str The Amazon Resource Name (ARN) of the Outpost.
- owner_
id str The ID of the AWS account that owns the subnet.
- Dict[str, str]
A map of tags to assign to the resource.
- vpc_
id str The VPC ID.
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.