Subnet class

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. To allow for successful deletion, the provider will wait for at least 45 minutes even if a shorter delete timeout is specified.

> NOTE: When AWS GuardDuty is enabled in your account, it automatically creates VPC endpoints in your VPCs to monitor network traffic. During subnet deletion, the provider automatically detects and dissociates the subnet from these GuardDuty-managed VPC endpoints if they are blocking the deletion, preserving GuardDuty protection for other subnets in the VPC. This cleanup only targets resources tagged with GuardDutyManaged=true and happens automatically during destroy operations with no manual intervention required. For optimal functionality, the IAM role used by Terraform should have the optional permissions listed below. If these permissions are not available, the provider will continue with the deletion attempt and surface warnings only if the deletion ultimately fails.

Example Usage

Basic Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const main = new aws.ec2.Subnet("main", {
    vpcId: mainAwsVpc.id,
    cidrBlock: "10.0.1.0/24",
    tags: {
        Name: "Main",
    },
});
import pulumi
import pulumi_aws as aws

main = aws.ec2.Subnet("main",
    vpc_id=main_aws_vpc["id"],
    cidr_block="10.0.1.0/24",
    tags={
        "Name": "Main",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var main = new Aws.Ec2.Subnet("main", new()
    {
        VpcId = mainAwsVpc.Id,
        CidrBlock = "10.0.1.0/24",
        Tags =
        {
            { "Name", "Main" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.NewSubnet(ctx, "main", &ec2.SubnetArgs{
			VpcId:     pulumi.Any(mainAwsVpc.Id),
			CidrBlock: pulumi.String("10.0.1.0/24"),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("Main"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_ec2_subnet" "main" {
  vpc_id     = mainAwsVpc.id
  cidr_block = "10.0.1.0/24"
  tags = {
    "Name" = "Main"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
        var main = new Subnet("main", SubnetArgs.builder()
            .vpcId(mainAwsVpc.id())
            .cidrBlock("10.0.1.0/24")
            .tags(Map.of("Name", "Main"))
            .build());

    }
}
resources:
  main:
    type: aws:ec2:Subnet
    properties:
      vpcId: ${mainAwsVpc.id}
      cidrBlock: 10.0.1.0/24
      tags:
        Name: Main

Subnets In Secondary VPC CIDR Blocks

When managing subnets in one of a VPC's secondary CIDR blocks created using a aws.ec2.VpcIpv4CidrBlockAssociation resource, it is recommended to reference that resource's vpcId attribute to ensure correct dependency ordering.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const secondaryCidr = new aws.ec2.VpcIpv4CidrBlockAssociation("secondary_cidr", {
    vpcId: main.id,
    cidrBlock: "172.20.0.0/16",
});
const inSecondaryCidr = new aws.ec2.Subnet("in_secondary_cidr", {
    vpcId: secondaryCidr.vpcId,
    cidrBlock: "172.20.0.0/24",
});
import pulumi
import pulumi_aws as aws

secondary_cidr = aws.ec2.VpcIpv4CidrBlockAssociation("secondary_cidr",
    vpc_id=main["id"],
    cidr_block="172.20.0.0/16")
in_secondary_cidr = aws.ec2.Subnet("in_secondary_cidr",
    vpc_id=secondary_cidr.vpc_id,
    cidr_block="172.20.0.0/24")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var secondaryCidr = new Aws.Ec2.VpcIpv4CidrBlockAssociation("secondary_cidr", new()
    {
        VpcId = main.Id,
        CidrBlock = "172.20.0.0/16",
    });

    var inSecondaryCidr = new Aws.Ec2.Subnet("in_secondary_cidr", new()
    {
        VpcId = secondaryCidr.VpcId,
        CidrBlock = "172.20.0.0/24",
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		secondaryCidr, err := ec2.NewVpcIpv4CidrBlockAssociation(ctx, "secondary_cidr", &ec2.VpcIpv4CidrBlockAssociationArgs{
			VpcId:     pulumi.Any(main.Id),
			CidrBlock: pulumi.String("172.20.0.0/16"),
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewSubnet(ctx, "in_secondary_cidr", &ec2.SubnetArgs{
			VpcId:     secondaryCidr.VpcId,
			CidrBlock: pulumi.String("172.20.0.0/24"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_ec2_vpcipv4cidrblockassociation" "secondary_cidr" {
  vpc_id     = main.id
  cidr_block = "172.20.0.0/16"
}
resource "aws_ec2_subnet" "in_secondary_cidr" {
  vpc_id     = aws_ec2_vpcipv4cidrblockassociation.secondary_cidr.vpc_id
  cidr_block = "172.20.0.0/24"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociation;
import com.pulumi.aws.ec2.VpcIpv4CidrBlockAssociationArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
        var secondaryCidr = new VpcIpv4CidrBlockAssociation("secondaryCidr", VpcIpv4CidrBlockAssociationArgs.builder()
            .vpcId(main.id())
            .cidrBlock("172.20.0.0/16")
            .build());

        var inSecondaryCidr = new Subnet("inSecondaryCidr", SubnetArgs.builder()
            .vpcId(secondaryCidr.vpcId())
            .cidrBlock("172.20.0.0/24")
            .build());

    }
}
resources:
  secondaryCidr:
    type: aws:ec2:VpcIpv4CidrBlockAssociation
    name: secondary_cidr
    properties:
      vpcId: ${main.id}
      cidrBlock: 172.20.0.0/16
  inSecondaryCidr:
    type: aws:ec2:Subnet
    name: in_secondary_cidr
    properties:
      vpcId: ${secondaryCidr.vpcId}
      cidrBlock: 172.20.0.0/24

IPAM-Managed Subnets

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const current = aws.getRegion({});
const test = new aws.ec2.VpcIpam("test", {operatingRegions: [{
    regionName: current.then(current => current.region),
}]});
const testVpcIpamPool = new aws.ec2.VpcIpamPool("test", {
    addressFamily: "ipv4",
    ipamScopeId: test.privateDefaultScopeId,
    locale: current.then(current => current.region),
});
const testVpcIpamPoolCidr = new aws.ec2.VpcIpamPoolCidr("test", {
    ipamPoolId: testVpcIpamPool.id,
    cidr: "10.0.0.0/16",
});
const testVpc = new aws.ec2.Vpc("test", {
    ipv4IpamPoolId: testVpcIpamPool.id,
    ipv4NetmaskLength: 24,
}, {
    dependsOn: [testVpcIpamPoolCidr],
});
const vpc = new aws.ec2.VpcIpamPool("vpc", {
    sourceResource: {
        resourceId: testVpc.id,
        resourceOwner: currentAwsCallerIdentity.accountId,
        resourceRegion: current.then(current => current.region),
        resourceType: "vpc",
    },
    addressFamily: "ipv4",
    ipamScopeId: test.privateDefaultScopeId,
    locale: current.then(current => current.region),
    sourceIpamPoolId: testVpcIpamPool.id,
});
const vpcVpcIpamPoolCidr = new aws.ec2.VpcIpamPoolCidr("vpc", {
    ipamPoolId: vpc.id,
    cidr: testVpc.cidrBlock,
});
const testSubnet = new aws.ec2.Subnet("test", {
    vpcId: testVpc.id,
    ipv4IpamPoolId: vpc.id,
    ipv4NetmaskLength: 28,
    availabilityZone: available.names[0],
}, {
    dependsOn: [vpcVpcIpamPoolCidr],
});
import pulumi
import pulumi_aws as aws

current = aws.get_region()
test = aws.ec2.VpcIpam("test", operating_regions=[{
    "region_name": current.region,
}])
test_vpc_ipam_pool = aws.ec2.VpcIpamPool("test",
    address_family="ipv4",
    ipam_scope_id=test.private_default_scope_id,
    locale=current.region)
test_vpc_ipam_pool_cidr = aws.ec2.VpcIpamPoolCidr("test",
    ipam_pool_id=test_vpc_ipam_pool.id,
    cidr="10.0.0.0/16")
test_vpc = aws.ec2.Vpc("test",
    ipv4_ipam_pool_id=test_vpc_ipam_pool.id,
    ipv4_netmask_length=24,
    opts = pulumi.ResourceOptions(depends_on=[test_vpc_ipam_pool_cidr]))
vpc = aws.ec2.VpcIpamPool("vpc",
    source_resource={
        "resource_id": test_vpc.id,
        "resource_owner": current_aws_caller_identity["accountId"],
        "resource_region": current.region,
        "resource_type": "vpc",
    },
    address_family="ipv4",
    ipam_scope_id=test.private_default_scope_id,
    locale=current.region,
    source_ipam_pool_id=test_vpc_ipam_pool.id)
vpc_vpc_ipam_pool_cidr = aws.ec2.VpcIpamPoolCidr("vpc",
    ipam_pool_id=vpc.id,
    cidr=test_vpc.cidr_block)
test_subnet = aws.ec2.Subnet("test",
    vpc_id=test_vpc.id,
    ipv4_ipam_pool_id=vpc.id,
    ipv4_netmask_length=28,
    availability_zone=available["names"][0],
    opts = pulumi.ResourceOptions(depends_on=[vpc_vpc_ipam_pool_cidr]))
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var current = Aws.GetRegion.Invoke();

    var test = new Aws.Ec2.VpcIpam("test", new()
    {
        OperatingRegions = new[]
        {
            new Aws.Ec2.Inputs.VpcIpamOperatingRegionArgs
            {
                RegionName = current.Apply(getRegionResult => getRegionResult.Region),
            },
        },
    });

    var testVpcIpamPool = new Aws.Ec2.VpcIpamPool("test", new()
    {
        AddressFamily = "ipv4",
        IpamScopeId = test.PrivateDefaultScopeId,
        Locale = current.Apply(getRegionResult => getRegionResult.Region),
    });

    var testVpcIpamPoolCidr = new Aws.Ec2.VpcIpamPoolCidr("test", new()
    {
        IpamPoolId = testVpcIpamPool.Id,
        Cidr = "10.0.0.0/16",
    });

    var testVpc = new Aws.Ec2.Vpc("test", new()
    {
        Ipv4IpamPoolId = testVpcIpamPool.Id,
        Ipv4NetmaskLength = 24,
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            testVpcIpamPoolCidr,
        },
    });

    var vpc = new Aws.Ec2.VpcIpamPool("vpc", new()
    {
        SourceResource = new Aws.Ec2.Inputs.VpcIpamPoolSourceResourceArgs
        {
            ResourceId = testVpc.Id,
            ResourceOwner = currentAwsCallerIdentity.AccountId,
            ResourceRegion = current.Apply(getRegionResult => getRegionResult.Region),
            ResourceType = "vpc",
        },
        AddressFamily = "ipv4",
        IpamScopeId = test.PrivateDefaultScopeId,
        Locale = current.Apply(getRegionResult => getRegionResult.Region),
        SourceIpamPoolId = testVpcIpamPool.Id,
    });

    var vpcVpcIpamPoolCidr = new Aws.Ec2.VpcIpamPoolCidr("vpc", new()
    {
        IpamPoolId = vpc.Id,
        Cidr = testVpc.CidrBlock,
    });

    var testSubnet = new Aws.Ec2.Subnet("test", new()
    {
        VpcId = testVpc.Id,
        Ipv4IpamPoolId = vpc.Id,
        Ipv4NetmaskLength = 28,
        AvailabilityZone = available.Names[0],
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            vpcVpcIpamPoolCidr,
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		current, err := aws.GetRegion(ctx, &aws.GetRegionArgs{}, nil)
		if err != nil {
			return err
		}
		test, err := ec2.NewVpcIpam(ctx, "test", &ec2.VpcIpamArgs{
			OperatingRegions: ec2.VpcIpamOperatingRegionArray{
				&ec2.VpcIpamOperatingRegionArgs{
					RegionName: pulumi.String(current.Region),
				},
			},
		})
		if err != nil {
			return err
		}
		testVpcIpamPool, err := ec2.NewVpcIpamPool(ctx, "test", &ec2.VpcIpamPoolArgs{
			AddressFamily: pulumi.String("ipv4"),
			IpamScopeId:   test.PrivateDefaultScopeId,
			Locale:        pulumi.String(current.Region),
		})
		if err != nil {
			return err
		}
		testVpcIpamPoolCidr, err := ec2.NewVpcIpamPoolCidr(ctx, "test", &ec2.VpcIpamPoolCidrArgs{
			IpamPoolId: testVpcIpamPool.ID().ToIDOutput().ToStringOutput(),
			Cidr:       pulumi.String("10.0.0.0/16"),
		})
		if err != nil {
			return err
		}
		testVpc, err := ec2.NewVpc(ctx, "test", &ec2.VpcArgs{
			Ipv4IpamPoolId:    testVpcIpamPool.ID().ToIDOutput().ToStringOutput(),
			Ipv4NetmaskLength: pulumi.Int(24),
		}, pulumi.DependsOn([]pulumi.Resource{
			testVpcIpamPoolCidr,
		}))
		if err != nil {
			return err
		}
		vpc, err := ec2.NewVpcIpamPool(ctx, "vpc", &ec2.VpcIpamPoolArgs{
			SourceResource: &ec2.VpcIpamPoolSourceResourceArgs{
				ResourceId:     testVpc.ID().ToIDOutput().ToStringOutput(),
				ResourceOwner:  pulumi.Any(currentAwsCallerIdentity.AccountId),
				ResourceRegion: pulumi.String(current.Region),
				ResourceType:   pulumi.String("vpc"),
			},
			AddressFamily:    pulumi.String("ipv4"),
			IpamScopeId:      test.PrivateDefaultScopeId,
			Locale:           pulumi.String(current.Region),
			SourceIpamPoolId: testVpcIpamPool.ID().ToIDOutput().ToStringOutput(),
		})
		if err != nil {
			return err
		}
		vpcVpcIpamPoolCidr, err := ec2.NewVpcIpamPoolCidr(ctx, "vpc", &ec2.VpcIpamPoolCidrArgs{
			IpamPoolId: vpc.ID().ToIDOutput().ToStringOutput(),
			Cidr:       testVpc.CidrBlock,
		})
		if err != nil {
			return err
		}
		_, err = ec2.NewSubnet(ctx, "test", &ec2.SubnetArgs{
			VpcId:             testVpc.ID().ToIDOutput().ToStringOutput(),
			Ipv4IpamPoolId:    vpc.ID().ToIDOutput().ToStringOutput(),
			Ipv4NetmaskLength: pulumi.Int(28),
			AvailabilityZone:  pulumi.Any(available.Names[0]),
		}, pulumi.DependsOn([]pulumi.Resource{
			vpcVpcIpamPoolCidr,
		}))
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_getregion" "current" {
}

resource "aws_ec2_vpcipam" "test" {
  operating_regions {
    region_name = data.aws_getregion.current.region
  }
}
resource "aws_ec2_vpcipampool" "test" {
  address_family = "ipv4"
  ipam_scope_id  = aws_ec2_vpcipam.test.private_default_scope_id
  locale         = data.aws_getregion.current.region
}
resource "aws_ec2_vpcipampoolcidr" "test" {
  ipam_pool_id = aws_ec2_vpcipampool.test.id
  cidr         = "10.0.0.0/16"
}
resource "aws_ec2_vpc" "test" {
  depends_on          = [aws_ec2_vpcipampoolcidr.test]
  ipv4_ipam_pool_id   = aws_ec2_vpcipampool.test.id
  ipv4_netmask_length = 24
}
resource "aws_ec2_vpcipampool" "vpc" {
  source_resource = {
    resource_id     = aws_ec2_vpc.test.id
    resource_owner  = currentAwsCallerIdentity.accountId
    resource_region = data.aws_getregion.current.region
    resource_type   = "vpc"
  }
  address_family      = "ipv4"
  ipam_scope_id       = aws_ec2_vpcipam.test.private_default_scope_id
  locale              = data.aws_getregion.current.region
  source_ipam_pool_id = aws_ec2_vpcipampool.test.id
}
resource "aws_ec2_vpcipampoolcidr" "vpc" {
  ipam_pool_id = aws_ec2_vpcipampool.vpc.id
  cidr         = aws_ec2_vpc.test.cidr_block
}
resource "aws_ec2_subnet" "test" {
  depends_on          = [aws_ec2_vpcipampoolcidr.vpc]
  vpc_id              = aws_ec2_vpc.test.id
  ipv4_ipam_pool_id   = aws_ec2_vpcipampool.vpc.id
  ipv4_netmask_length = 28
  availability_zone   = available.names[0]
}
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.GetRegionArgs;
import com.pulumi.aws.ec2.VpcIpam;
import com.pulumi.aws.ec2.VpcIpamArgs;
import com.pulumi.aws.ec2.inputs.VpcIpamOperatingRegionArgs;
import com.pulumi.aws.ec2.VpcIpamPool;
import com.pulumi.aws.ec2.VpcIpamPoolArgs;
import com.pulumi.aws.ec2.VpcIpamPoolCidr;
import com.pulumi.aws.ec2.VpcIpamPoolCidrArgs;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.inputs.VpcIpamPoolSourceResourceArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
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 current = AwsFunctions.getRegion(GetRegionArgs.builder()
            .build());

        var test = new VpcIpam("test", VpcIpamArgs.builder()
            .operatingRegions(VpcIpamOperatingRegionArgs.builder()
                .regionName(current.region())
                .build())
            .build());

        var testVpcIpamPool = new VpcIpamPool("testVpcIpamPool", VpcIpamPoolArgs.builder()
            .addressFamily("ipv4")
            .ipamScopeId(test.privateDefaultScopeId())
            .locale(current.region())
            .build());

        var testVpcIpamPoolCidr = new VpcIpamPoolCidr("testVpcIpamPoolCidr", VpcIpamPoolCidrArgs.builder()
            .ipamPoolId(testVpcIpamPool.id())
            .cidr("10.0.0.0/16")
            .build());

        var testVpc = new Vpc("testVpc", VpcArgs.builder()
            .ipv4IpamPoolId(testVpcIpamPool.id())
            .ipv4NetmaskLength(24)
            .build(), CustomResourceOptions.builder()
                .dependsOn(testVpcIpamPoolCidr)
                .build());

        var vpc = new VpcIpamPool("vpc", VpcIpamPoolArgs.builder()
            .sourceResource(VpcIpamPoolSourceResourceArgs.builder()
                .resourceId(testVpc.id())
                .resourceOwner(currentAwsCallerIdentity.accountId())
                .resourceRegion(current.region())
                .resourceType("vpc")
                .build())
            .addressFamily("ipv4")
            .ipamScopeId(test.privateDefaultScopeId())
            .locale(current.region())
            .sourceIpamPoolId(testVpcIpamPool.id())
            .build());

        var vpcVpcIpamPoolCidr = new VpcIpamPoolCidr("vpcVpcIpamPoolCidr", VpcIpamPoolCidrArgs.builder()
            .ipamPoolId(vpc.id())
            .cidr(testVpc.cidrBlock())
            .build());

        var testSubnet = new Subnet("testSubnet", SubnetArgs.builder()
            .vpcId(testVpc.id())
            .ipv4IpamPoolId(vpc.id())
            .ipv4NetmaskLength(28)
            .availabilityZone(available.names()[0])
            .build(), CustomResourceOptions.builder()
                .dependsOn(vpcVpcIpamPoolCidr)
                .build());

    }
}
resources:
  test:
    type: aws:ec2:VpcIpam
    properties:
      operatingRegions:
        - regionName: ${current.region}
  testVpcIpamPool:
    type: aws:ec2:VpcIpamPool
    name: test
    properties:
      addressFamily: ipv4
      ipamScopeId: ${test.privateDefaultScopeId}
      locale: ${current.region}
  testVpcIpamPoolCidr:
    type: aws:ec2:VpcIpamPoolCidr
    name: test
    properties:
      ipamPoolId: ${testVpcIpamPool.id}
      cidr: 10.0.0.0/16
  testVpc:
    type: aws:ec2:Vpc
    name: test
    properties:
      ipv4IpamPoolId: ${testVpcIpamPool.id}
      ipv4NetmaskLength: 24
    options:
      dependsOn:
        - ${testVpcIpamPoolCidr}
  vpc:
    type: aws:ec2:VpcIpamPool
    properties:
      sourceResource:
        resourceId: ${testVpc.id}
        resourceOwner: ${currentAwsCallerIdentity.accountId}
        resourceRegion: ${current.region}
        resourceType: vpc
      addressFamily: ipv4
      ipamScopeId: ${test.privateDefaultScopeId}
      locale: ${current.region}
      sourceIpamPoolId: ${testVpcIpamPool.id}
  vpcVpcIpamPoolCidr:
    type: aws:ec2:VpcIpamPoolCidr
    name: vpc
    properties:
      ipamPoolId: ${vpc.id}
      cidr: ${testVpc.cidrBlock}
  testSubnet:
    type: aws:ec2:Subnet
    name: test
    properties:
      vpcId: ${testVpc.id}
      ipv4IpamPoolId: ${vpc.id}
      ipv4NetmaskLength: 28
      availabilityZone: ${available.names[0]}
    options:
      dependsOn:
        - ${vpcVpcIpamPoolCidr}
variables:
  current:
    fn::invoke:
      function: aws:getRegion
      arguments: {}

Import

Identity Schema

Required

  • id (String) ID of the subnet.

Optional

  • accountId (String) AWS Account where this resource is managed.
  • region (String) Region where this resource is managed.

Using pulumi import, import subnets using the subnet id. For example:

$ pulumi import aws:ec2/subnet:Subnet example subnet-9d4a7b6c

Constructors

Subnet(String name, {SubnetArgs? args, CustomResourceOptions? options})
Creates a new Subnet. name The Pulumi resource name. args Arguments used to configure this Subnet. The set of arguments for Subnet. options Resource options controlling this resource's behavior.
Subnet.reference(String urn)
Creates a typed reference to an existing Subnet resource.

Properties

arn ↔ Output<String>
The ARN of the subnet.
latefinal
assignIpv6AddressOnCreation ↔ Output<bool?>
Specify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. Default is false
latefinal
availabilityZone ↔ Output<String>
AZ for the subnet.
latefinal
availabilityZoneId ↔ Output<String>
AZ ID of the subnet. This argument is not supported in all regions or partitions. If necessary, use availabilityZone instead.
latefinal
childResources → Set<Resource>
finalinherited
cidrBlock ↔ Output<String>
The IPv4 CIDR block for the subnet.
latefinal
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
customerOwnedIpv4Pool ↔ Output<String?>
The customer owned IPv4 address pool. Typically used with the mapCustomerOwnedIpOnLaunch argument. The outpostArn argument must be specified when configured.
latefinal
enableDns64 ↔ Output<bool?>
Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations. Default: false.
latefinal
enableLniAtDeviceIndex ↔ Output<int?>
Indicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). A local network interface cannot be the primary network interface (eth0).
latefinal
enableResourceNameDnsAaaaRecordOnLaunch ↔ Output<bool?>
Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records. Default: false.
latefinal
enableResourceNameDnsARecordOnLaunch ↔ Output<bool?>
Indicates whether to respond to DNS queries for instance hostnames with DNS A records. Default: false.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
ipv4IpamPoolId ↔ Output<String?>
ID of an IPv4 VPC Resource Planning IPAM Pool. The CIDR of this pool is used to allocate the CIDR for the subnet.
latefinal
ipv4NetmaskLength ↔ Output<int?>
Netmask. Requires specifying a ipv4IpamPoolId.
latefinal
ipv6CidrBlock ↔ Output<String>
The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length. If the existing IPv6 subnet was created with assignIpv6AddressOnCreation = true, changing this value will force resource recreation.
latefinal
ipv6CidrBlockAssociationId ↔ Output<String>
The association ID for the IPv6 CIDR block.
latefinal
ipv6IpamPoolId ↔ Output<String?>
ID of an IPv6 VPC Resource Planning IPAM Pool. The CIDR of this pool is used to allocate the CIDR for the subnet.
latefinal
ipv6Native ↔ Output<bool?>
Indicates whether to create an IPv6-only subnet. Default: false.
latefinal
ipv6NetmaskLength ↔ Output<int?>
Netmask. Requires specifying a ipv6IpamPoolId. Valid values are from 44 to 64 in increments of 4.
latefinal
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
mapCustomerOwnedIpOnLaunch ↔ Output<bool?>
Specify true to indicate that network interfaces created in the subnet should be assigned a customer owned IP address. The customerOwnedIpv4Pool and outpostArn arguments must be specified when set to true. Default is false.
latefinal
mapPublicIpOnLaunch ↔ Output<bool?>
Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.
latefinal
outpostArn ↔ Output<String?>
ARN of the Outpost.
latefinal
ownerId ↔ Output<String>
The ID of the AWS account that owns the subnet.
latefinal
privateDnsHostnameTypeOnLaunch ↔ Output<String>
The type of hostnames to assign to instances in the subnet at launch. For IPv6-only subnets, an instance DNS name must be based on the instance ID. For dual-stack and IPv4-only subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values: ip-name, resource-name.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tags ↔ Output<Map<String, String>?>
A map of tags to assign to the resource. .If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
vpcId ↔ Output<String>
The VPC ID.
latefinal

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {SubnetState? state, CustomResourceOptions? options}) → Subnet
Gets an existing Subnet resource's state with the given name and id.