04-Route Tables & Peering
Module creating Route Tables and VPC Peering with Build VPC
Stage Modulemodules/04-route-tables-peering
Purpose
Creates route tables for subnets and sets up VPC Peering with Build VPC to enable communication between the 2 VPCs.
Created Resources
| Resource | Description |
|---|---|
| aws_route_table.main | Route table for main subnet |
| aws_route_table.second | Route table for second subnet |
| aws_route.internet_main | Route 0.0.0.0/0 → IGW (main) |
| aws_route.internet_second | Route 0.0.0.0/0 → IGW (second) |
| aws_vpc_peering_connection.build | VPC Peering with Build VPC (optional) |
| aws_route.to_build | Route to Build VPC via peering |
VPC Peering
VPC Peering is only created when peer_build_vpc_id is not empty:
VPC Peering Configuration
# terraform.tfvars
peer_build_vpc_id = "vpc-xxxxxxxxx" # VPC ID to peer with
peer_build_vpc_cidr = "172.31.0.0/16" # CIDR of peer VPC
peer_region = "" # Empty = same region
# Leave peer_build_vpc_id empty to disable peering
peer_build_vpc_id = ""Info
When VPC Peering is enabled, preflight-check.ps1 (Check 7b) will automatically scan the Build VPC route table to suggest a non-conflicting stage_index.
Route Table Rules
| Route Table | Destination | Target |
|---|---|---|
| milu2stage-main-rt | STAGE_VPC_CIDR | local |
| milu2stage-main-rt | 0.0.0.0/0 | Internet Gateway |
| milu2stage-main-rt | PEER_BUILD_VPC_CIDR | VPC Peering |
| milu2stage-second-rt | STAGE_VPC_CIDR | local |
| milu2stage-second-rt | 0.0.0.0/0 | Internet Gateway |