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

ResourceMô tả
aws_route_table.mainRoute table cho subnet main
aws_route_table.secondRoute table cho subnet second
aws_route.internet_mainRoute 0.0.0.0/0 → IGW (main)
aws_route.internet_secondRoute 0.0.0.0/0 → IGW (second)
aws_vpc_peering_connection.buildVPC Peering với Build VPC (optional)
aws_route.to_buildRoute 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 TableDestinationTarget
milu2stage-main-rtSTAGE_VPC_CIDRlocal
milu2stage-main-rt0.0.0.0/0Internet Gateway
milu2stage-main-rtPEER_BUILD_VPC_CIDRVPC Peering
milu2stage-second-rtSTAGE_VPC_CIDRlocal
milu2stage-second-rt0.0.0.0/0Internet Gateway