Route Table Architecture
The module implements a dual-route-table strategy with distinct routing behavior for public and private network tiers.Public Route Table
A single shared route table serves all public subnets across all Availability Zones. Resource:aws_route_table.public (main.tf:18-25)
Routing Configuration:
- Default Route: 0.0.0.0/0 → Internet Gateway (main.tf:27-33)
- Local Route: VPC CIDR → local (automatically created by AWS)
- VGW Propagation: Supports VPN route propagation via
public_propagating_vgws
aws_subnet.public instances (main.tf:197-202)
The public route table is created only when
length(var.public_subnets) > 0, making it optional based on your architecture needs.Private Route Tables
The module creates one route table per Availability Zone for private subnet isolation and independent NAT Gateway routing. Resource:aws_route_table.private (main.tf:43-50)
Count: length(var.azs) - One per Availability Zone
Routing Configuration:
- Default Route (when NAT enabled): 0.0.0.0/0 → NAT Gateway (main.tf:35-41)
- Local Route: VPC CIDR → local
- VGW Propagation: Supports VPN route propagation via
private_propagating_vgws
- Private subnets (
aws_subnet.private) - Database subnets (
aws_subnet.database) - ElastiCache subnets (
aws_subnet.elasticache)
Traffic Flows
Public Subnet Traffic Flow
Inbound Internet Traffic:- Public subnets have
map_public_ip_on_launch = trueby default (main.tf:106) - Instances receive public IPv4 addresses automatically
- Security groups control inbound/outbound access
- Route table association: main.tf:197-202
Private Subnet Traffic Flow
Outbound Internet Traffic (NAT Gateway enabled):- Each private route table routes to its corresponding AZ’s NAT Gateway (main.tf:38)
- NAT Gateway performs source NAT using its Elastic IP
- Return traffic flows back through the same NAT Gateway
- No inbound connections from internet possible
- Only from within VPC (local routes)
- Or from VPN/DirectConnect (VGW propagated routes)
Private subnets cannot receive inbound connections from the internet, even with NAT Gateways. NAT only enables outbound connectivity for software updates, API calls, etc.
Database Subnet Traffic Flow
Database subnets share route tables with private subnets in the same AZ (main.tf:183-188). Outbound Traffic:- OS and database engine patching
- Custom database extensions downloads
- Backup to S3 (can be optimized with VPC endpoint)
- Uses VPC local routing
- Controlled by security groups and NACLs
ElastiCache Subnet Traffic Flow
ElastiCache subnets follow the same routing pattern as database subnets (main.tf:190-195). Cache Access Pattern:NAT Gateway Deployment Models
The module supports two NAT Gateway architectures controlled byenable_nat_gateway and single_nat_gateway.
High Availability Mode (Recommended)
Configuration:- One NAT Gateway per Availability Zone (main.tf:117-124)
- One Elastic IP per NAT Gateway (main.tf:111-115)
- Each private route table routes to its AZ’s NAT Gateway (main.tf:38)
- us-east-1a private subnets → NAT Gateway in us-east-1a
- us-east-1b private subnets → NAT Gateway in us-east-1b
- us-east-1c private subnets → NAT Gateway in us-east-1c
- AZ-independent failure domains
- No cross-AZ data transfer charges for NAT traffic
- Higher aggregate bandwidth
Single NAT Gateway Mode (Cost-Optimized)
Configuration:- One NAT Gateway in first Availability Zone (main.tf:118, 121)
- One Elastic IP (main.tf:112)
- All private route tables route to the single NAT Gateway (main.tf:38)
- All private subnets in all AZs → NAT Gateway in us-east-1a
- Lower cost (97.20/month for 3 AZs)
- Simplified architecture
- Single point of failure for all outbound internet traffic
- Cross-AZ data transfer charges apply
- Bandwidth limited to single NAT Gateway capacity
Single NAT Gateway mode should only be used for development/testing environments. Production workloads should use high availability mode to meet uptime requirements.
VPC Endpoints
Gateway endpoints provide private connectivity to AWS services without traversing NAT Gateways or the internet.S3 VPC Endpoint
Resource:aws_vpc_endpoint.s3 (main.tf:130-135)
Route Table Associations:
- Private route tables: main.tf:137-142
- Public route table: main.tf:144-149
- No NAT Gateway data processing charges for S3 traffic
- Lower latency through AWS backbone network
- S3 traffic never leaves AWS network
- Supports bucket policies restricting access to specific VPC endpoint
DynamoDB VPC Endpoint
Resource:aws_vpc_endpoint.dynamodb (main.tf:155-160)
Route Table Associations:
- Private route tables: main.tf:162-167
- Public route table: main.tf:169-174
- No NAT Gateway charges for DynamoDB API calls
- Enhanced security through VPC endpoint policies
- Reduced NAT Gateway bandwidth utilization
Subnet CIDR Planning
The module requires careful CIDR planning to avoid subnet exhaustion.Recommended CIDR Allocation
For a VPC with 3 Availability Zones: VPC: 10.0.0.0/16 (65,536 IPs) Public Subnets (256 IPs each):- us-east-1a: 10.0.0.0/24
- us-east-1b: 10.0.1.0/24
- us-east-1c: 10.0.2.0/24
- us-east-1a: 10.0.16.0/20
- us-east-1b: 10.0.32.0/20
- us-east-1c: 10.0.48.0/20
- us-east-1a: 10.0.64.0/24
- us-east-1b: 10.0.65.0/24
- us-east-1c: 10.0.66.0/24
- us-east-1a: 10.0.67.0/24
- us-east-1b: 10.0.68.0/24
- us-east-1c: 10.0.69.0/24
AWS reserves 5 IP addresses in each subnet (network, broadcast, DNS, future use, and gateway), so a /24 subnet provides 251 usable IPs, not 256.
Subnet Sizing Guidelines
Public Subnets: /24 (251 usable IPs)- Typically host load balancers and NAT Gateways
- Low IP address consumption
- EKS requires at least /27 per subnet for service load balancers
- Largest IP consumer (application instances, containers, Lambda ENIs)
- ECS/EKS clusters can consume hundreds of IPs per node
- Lambda functions create ENIs in VPC
- RDS Multi-AZ uses 2 IPs per database
- Aurora clusters use 1 IP per instance
- Reserved capacity for scaling
- Each cache node requires 1 IP
- Cluster mode can scale to dozens of nodes
Route Table Association Logic
The module associates subnets to route tables based on subnet tier and Availability Zone.Public Subnet Associations
Code: main.tf:197-202Private Subnet Associations
Code: main.tf:176-181Database Subnet Associations
Code: main.tf:183-188Database and ElastiCache subnets use the private route tables, not separate route tables. They inherit the same NAT Gateway routing as private subnets.