AWS Amazon EC2 Subnet

This page shows how to write Terraform and CloudFormation for Amazon EC2 Subnet and write them securely.

code-icon

Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.

get-started-button

Terraform Example (aws_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. Terraform AWS Provider version 2.31.0 and later automatically handles this increased timeout, however prior versions require setting the customizable deletion timeout to 45 minutes (delete = "45m"). AWS and HashiCorp are working together to reduce the amount of time required for resource deletion and updates can be tracked in this GitHub issue.

Parameters

Example Usage (from GitHub)

github-iconmdigbazova/terraforming-4ha-live-all-resources
resource "aws_subnet" "subnet-dev-nat-eu-central-1a" {
    //-09101cb3af5e1772a
    vpc_id                  = aws_vpc.vpc-ha-dev.id
    cidr_block              = "172.31.112.0/24"
    availability_zone       = "eu-central-1a"
    map_public_ip_on_launch = false

CloudFormation Example (AWS::EC2::Subnet)

Specifies a subnet for a VPC.

When you create each subnet, you provide the VPC ID and IPv4 CIDR block for the subnet. After you create a subnet, you can't change its CIDR block. The size of the subnet's IPv4 CIDR block can be the same as a VPC's IPv4 CIDR block, or a subset of a VPC's IPv4 CIDR block. If you create more than one subnet in a VPC, the subnets' CIDR blocks must not overlap. The smallest IPv4 subnet (and VPC) you can create uses a /28 netmask (16 IPv4 addresses), and the largest uses a /16 netmask (65,536 IPv4 addresses).

If you've associated an IPv6 CIDR block with your VPC, you can create a subnet with an IPv6 CIDR block that uses a /64 prefix length.

Parameters

Frequently asked questions

What is AWS Amazon EC2 Subnet?

AWS Amazon EC2 Subnet is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Subnet?

For Terraform, the mdigbazova/terraforming-4ha-live-all-resources source code example is useful. See the Terraform Example section for further details.