Skip to content

VPC Peering Walkthrough

VPC Peering is an L3 point-to-point pattern. Cross-account peering requires the accepter (shared-services) to accept the connection, then a separate consumer apply to enable requester-side DNS resolution so the consumer can resolve the shared internal ALB hostname.

  • Shared-services CIDR: 10.10.0.0/16
  • Consumer CIDR: 10.20.0.0/16
  • Region: ap-southeast-2

VPC Peering architecture showing two peered VPCs with route tables and cross-account connectivity

Upstream Terraform directory is peering:

Step 1 — Shared-Services Apply (VPC + App)

Section titled “Step 1 — Shared-Services Apply (VPC + App)”

Creates the provider VPC, internal ALB, demo API, and security groups — but not yet the peering connection.

Terminal window
export AWS_REGION=ap-southeast-2
export DEV_ACCOUNT_ID=987654321098
AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services init
AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services apply \
-var="consumer_account_id=$DEV_ACCOUNT_ID"

Capture outputs:

Terminal window
export SHARED_SERVICES_ACCOUNT_ID=$(AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services output -raw account_id)
export SHARED_SERVICES_VPC_ID=$(AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services output -raw vpc_id)
export ALB_DNS_NAME=$(AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services output -raw alb_dns_name)

Example outputs:

account_id = 123456789012
vpc_id = vpc-EXAMPLE1234567890
alb_dns_name = internal-apcp-peer-ss-app-alb-EXAMPLE.ap-southeast-2.elb.amazonaws.com

Step 2 — Consumer Apply (Create Peering Request)

Section titled “Step 2 — Consumer Apply (Create Peering Request)”

Creates the consumer VPC, initiates the cross-account peering connection, and adds consumer-side routes.

Terminal window
AWS_PROFILE=dev terraform -chdir=terraform/patterns/peering/consumer init
AWS_PROFILE=dev terraform -chdir=terraform/patterns/peering/consumer apply \
-var="shared_services_account_id=$SHARED_SERVICES_ACCOUNT_ID" \
-var="shared_services_vpc_id=$SHARED_SERVICES_VPC_ID"

Capture the peering connection ID:

Terminal window
export PEERING_CONNECTION_ID=$(AWS_PROFILE=dev terraform -chdir=terraform/patterns/peering/consumer output -raw peering_connection_id)

Example output:

peering_connection_id = pcx-EXAMPLE1234567890

Step 3 — Shared-Services Apply (Accept Peering)

Section titled “Step 3 — Shared-Services Apply (Accept Peering)”

Re-applies shared-services with the peering connection ID to accept the connection, add accepter routes, and update ALB security groups.

Terminal window
AWS_PROFILE=shared-services terraform -chdir=terraform/patterns/peering/shared-services apply \
-var="consumer_account_id=$DEV_ACCOUNT_ID" \
-var="peering_connection_id=$PEERING_CONNECTION_ID"

Verify peering status:

Terminal window
AWS_PROFILE=shared-services aws ec2 describe-vpc-peering-connections \
--vpc-peering-connection-ids "$PEERING_CONNECTION_ID" \
--query "VpcPeeringConnections[0].Status.Code" \
--output text

Expected: active

Step 4 — Consumer Apply (Enable Requester DNS)

Section titled “Step 4 — Consumer Apply (Enable Requester DNS)”

Re-applies consumer with DNS resolution enabled on the requester side:

Terminal window
AWS_PROFILE=dev terraform -chdir=terraform/patterns/peering/consumer apply \
-var="shared_services_account_id=$SHARED_SERVICES_ACCOUNT_ID" \
-var="shared_services_vpc_id=$SHARED_SERVICES_VPC_ID" \
-var="enable_requester_dns=true"
StepProfileAction
1shared-servicesProvider VPC, ALB, demo API
2devConsumer VPC, peering request, consumer routes
3shared-servicesAccept peering, accepter routes, ALB SG update
4devEnable requester-side DNS resolution

See Verification — VPC Peering for the SSM curl test against $ALB_DNS_NAME.

See Teardown — VPC Peering. Destroy consumer before shared-services.