04-Route Tables & Peering
Module tạo Route Tables và VPC Peering với Build VPC
Stage Modulemodules/04-route-tables-peering
Mục đích
Tạo route tables cho các subnets và thiết lập VPC Peering với Build VPC để cho phép giao tiếp giữa 2 VPC.
Resources được tạo
| Resource | Mô tả |
|---|---|
| aws_route_table.main | Route table cho subnet main |
| aws_route_table.second | Route table cho subnet second |
| 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 với Build VPC (optional) |
| aws_route.to_build | Route tới Build VPC qua peering |
VPC Peering
VPC Peering chỉ được tạo khi peer_build_vpc_id không trống:
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 = ""Thông tin
Khi VPC Peering được bật, preflight-check.ps1 (Check 7b) sẽ tự động scan route table của Build VPC để đề xuất stage_index không xung đột CIDR.
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 |