Planton logoPlanton

Loading...

AWS Subnet

Deploy a single subnet into an AWS VPC, with its routing folded in. A subnet is an Availability-Zone-scoped slice of a VPC's IP space and the placement target for EC2, load balancers, RDS, EKS/ECS, and most other AWS workloads.

What Gets Created

  • An EC2 subnet in the chosen VPC and Availability Zone, with the given IPv4 CIDR (and optional IPv6 CIDR).
  • When routes is set: a dedicated route table owned by the subnet, populated with your rules, plus the route-table association linking it to the subnet.
  • When routeTableId is set: a route-table association to that existing table.
  • When neither is set: nothing extra — the subnet stays on the VPC main route table.

Prerequisites

  • An existing AwsVpc (or a literal vpc-id). The subnet's CIDR must fit within the VPC's CIDR.
  • For internet/NAT routes, the corresponding gateway must already exist; supply its id as the route targetId.

Quick Start

apiVersion: aws.planton.dev/v1
kind: AwsSubnet
metadata:
  name: app-private-usw2a
spec:
  region: us-west-2
  vpcId:
    valueFrom:
      kind: AwsVpc
      name: my-vpc
      fieldPath: status.outputs.vpc_id
  availabilityZone: us-west-2a
  cidrBlock: 10.0.1.0/24

Configuration Reference

Required

FieldDescription
regionAWS region (must match the VPC's region).
vpcIdThe VPC to create the subnet in. Literal id or a reference to an AwsVpc.
availabilityZoneThe AZ the subnet lives in (e.g. us-west-2a).
cidrBlockIPv4 CIDR within the VPC (e.g. 10.0.1.0/24).

Optional

FieldDescription
mapPublicIpOnLaunchAuto-assign a public IPv4 to instances launched here. Default false.
assignIpv6AddressOnCreationAuto-assign an IPv6 address. Requires ipv6CidrBlock. Default false.
ipv6CidrBlockIPv6 /64 for a dual-stack subnet.
enableDns64Enable DNS64 (NAT64) for IPv6-only egress to IPv4. Default false.
enableResourceNameDnsARecordOnLaunchDNS A record for instance resource names. Default false.
enableResourceNameDnsAaaaRecordOnLaunchDNS AAAA record for instance resource names. Default false.
privateDnsHostnameTypeOnLaunchip-name or resource-name.
routeTableIdAssociate an existing route table. Mutually exclusive with routes.
routesInline rules; creates a subnet-owned route table. Mutually exclusive with routeTableId.

Route (within routes)

FieldDescription
destinationCidrBlock / destinationIpv6CidrBlock / destinationPrefixListIdThe destination — set exactly one.
targetTypeinternet_gateway, nat_gateway, transit_gateway, vpc_peering_connection, vpc_endpoint, network_interface, or egress_only_internet_gateway.
targetIdThe target resource id (literal or reference).

Examples

Public subnet (default route to an internet gateway):

apiVersion: aws.planton.dev/v1
kind: AwsSubnet
metadata:
  name: public-usw2a
spec:
  region: us-west-2
  vpcId:
    value: vpc-0abc123
  availabilityZone: us-west-2a
  cidrBlock: 10.0.0.0/24
  mapPublicIpOnLaunch: true
  routes:
    - destinationCidrBlock: 0.0.0.0/0
      targetType: internet_gateway
      targetId:
        value: igw-0abc123

Private subnet (outbound via NAT gateway):

apiVersion: aws.planton.dev/v1
kind: AwsSubnet
metadata:
  name: private-usw2a
spec:
  region: us-west-2
  vpcId:
    value: vpc-0abc123
  availabilityZone: us-west-2a
  cidrBlock: 10.0.1.0/24
  routes:
    - destinationCidrBlock: 0.0.0.0/0
      targetType: nat_gateway
      targetId:
        value: nat-0abc123

Stack Outputs

OutputDescription
subnet_idThe subnet's id.
subnet_arnThe subnet's ARN.
availability_zoneThe AZ the subnet resides in.
cidr_blockThe subnet's IPv4 CIDR.
route_table_idThe associated route table (inline-created, external, or empty for the VPC main table).
regionThe region the subnet was created in.

Related Components

  • AwsVpc — the network the subnet belongs to.
  • AwsElasticIp — a stable public IP, e.g. for a NAT gateway a subnet routes to.
  • AwsTransitGateway — a route target for inter-VPC / hybrid connectivity.

Next article

AWS Transit Gateway

AWS Transit Gateway Deploys an AWS Transit Gateway with inline VPC attachments, replacing complex VPC peering meshes with a hub-and-spoke topology. The component bundles the Transit Gateway and its VPC attachments together because a TGW without attachments serves no purpose. Default routing behavior provides full-mesh connectivity out of the box. What Gets Created When you deploy an AwsTransitGateway resource, Planton provisions: Transit Gateway — an ec2transitgateway.TransitGateway resource...
Read next article
Presets
3 ready-to-deploy configurationsView presets →