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:

CidrBlock string

The CIDR block for the subnet.

VpcId string

The VPC ID.

AssignIpv6AddressOnCreation bool

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

AvailabilityZone string

The AZ for the subnet.

AvailabilityZoneId string

The AZ ID of the subnet.

Ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

MapPublicIpOnLaunch bool

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

Tags Dictionary<string, string>

A map of tags to assign to the resource.

CidrBlock string

The CIDR block for the subnet.

VpcId string

The VPC ID.

AssignIpv6AddressOnCreation bool

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

AvailabilityZone string

The AZ for the subnet.

AvailabilityZoneId string

The AZ ID of the subnet.

Ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

MapPublicIpOnLaunch bool

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

Tags map[string]string

A map of tags to assign to the resource.

cidrBlock string

The CIDR block for the subnet.

vpcId string

The VPC ID.

assignIpv6AddressOnCreation boolean

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

availabilityZone string

The AZ for the subnet.

availabilityZoneId string

The AZ ID of the subnet.

ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

mapPublicIpOnLaunch boolean

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

outpostArn string

The Amazon Resource Name (ARN) of the Outpost.

tags {[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_address_on_creation bool

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_id str

The AZ ID of the subnet.

ipv6_cidr_block str

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

map_public_ip_on_launch bool

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.

tags 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:

Arn string

The ARN of the subnet.

Id string
The provider-assigned unique ID for this managed resource.
Ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

OwnerId string

The ID of the AWS account that owns the subnet.

Arn string

The ARN of the subnet.

Id string
The provider-assigned unique ID for this managed resource.
Ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

OwnerId string

The ID of the AWS account that owns the subnet.

arn string

The ARN of the subnet.

id string
The provider-assigned unique ID for this managed resource.
ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

ownerId string

The ID of the AWS account that owns the subnet.

arn str

The ARN of the subnet.

id str
The provider-assigned unique ID for this managed resource.
ipv6_cidr_block_association_id str

The association ID for the IPv6 CIDR block.

owner_id str

The ID of the AWS account that owns the subnet.

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): Subnet
static 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.

AssignIpv6AddressOnCreation bool

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

AvailabilityZone string

The AZ for the subnet.

AvailabilityZoneId string

The AZ ID of the subnet.

CidrBlock string

The CIDR block for the subnet.

Ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

Ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

MapPublicIpOnLaunch bool

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

OwnerId string

The ID of the AWS account that owns the subnet.

Tags Dictionary<string, string>

A map of tags to assign to the resource.

VpcId string

The VPC ID.

Arn string

The ARN of the subnet.

AssignIpv6AddressOnCreation bool

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

AvailabilityZone string

The AZ for the subnet.

AvailabilityZoneId string

The AZ ID of the subnet.

CidrBlock string

The CIDR block for the subnet.

Ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

Ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

MapPublicIpOnLaunch bool

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

OwnerId string

The ID of the AWS account that owns the subnet.

Tags map[string]string

A map of tags to assign to the resource.

VpcId string

The VPC ID.

arn string

The ARN of the subnet.

assignIpv6AddressOnCreation boolean

Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false

availabilityZone string

The AZ for the subnet.

availabilityZoneId string

The AZ ID of the subnet.

cidrBlock string

The CIDR block for the subnet.

ipv6CidrBlock string

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

ipv6CidrBlockAssociationId string

The association ID for the IPv6 CIDR block.

mapPublicIpOnLaunch boolean

Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

outpostArn string

The Amazon Resource Name (ARN) of the Outpost.

ownerId string

The ID of the AWS account that owns the subnet.

tags {[key: string]: string}

A map of tags to assign to the resource.

vpcId string

The VPC ID.

arn str

The ARN of the subnet.

assign_ipv6_address_on_creation bool

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_id str

The AZ ID of the subnet.

cidr_block str

The CIDR block for the subnet.

ipv6_cidr_block str

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

ipv6_cidr_block_association_id str

The association ID for the IPv6 CIDR block.

map_public_ip_on_launch bool

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.

tags 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 aws Terraform Provider.