Review the purpose of a VPC without subnets

Check the VPC’s intended use and actual subnet configuration.

Description

Check the deployed VPC for subnets and confirm its intended use. Another stack may own the subnets, or the VPC may be reserved for later.

Potential impact

EC2 cannot launch an instance in a VPC that has no subnets.

Remediation

Add the subnets your workloads need. Before retiring an unused VPC, check what depends on it.

Examples

The second template creates a 10.0.0.0/24 subnet in myVPC2. To add a subnet to an existing VPC, keep its logical ID. Choose an Availability Zone, DNS, tenancy and routes appropriate to your environment.

Before

yaml
Resources:
  myVPC1:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: 'false'
      EnableDnsHostnames: 'false'
      InstanceTenancy: dedicated

After

yaml
Resources:
  myVPC2:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: 'false'
      EnableDnsHostnames: 'false'
      InstanceTenancy: dedicated

  mySubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId:
        Ref: myVPC2
      CidrBlock: 10.0.0.0/24
      AvailabilityZone: "us-east-1a"

References