Add subnet into existing default VPC with Terraform

  1. Define data source to retrieve an existing default AWS VPC:
    data "aws_vpc" "existing_vpc" {
      default = true
    }
  2. Declare an AWS subnet resource named dev-subnet.
    This subnet is associated with the retrieved existing VPC and configured with a specific CIDR block 172.31.48.0/20:
    resource "aws_subnet" "dev-subnet" {
      vpc_id = data.aws_vpc.existing_vpc.id
      cidr_block = "172.31.48.0/20"
      availability_zone = "eu-central-1a"
    }