Skip to content

VPC Peering

Category Cloud & AWS Networking
Status โœ… Completed
Repo nextwork-vpc-peering
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

๐Ÿ“š NextWork learning project. This is a practice project I built while working through NextWork's VPC Peering guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning โ€บ Cloud & AWS Networking
Status: โœ… Completed

Overview

This connects two VPCs (10.1.0.0/16 and 10.2.0.0/16) privately with a peering connection. The guide's key lesson is that peering alone isn't enough: each VPC's route table needs a route to the other's CIDR through the peering connection, and security groups must allow the traffic (ICMP for the ping test).

Summary

Deployed two VPCs (10.1.0.0/16 and 10.2.0.0/16) with an active peering connection on real AWS, and pinged VPC 2's instance by its private IP from VPC 1 (4/4 replies). Everything was torn down afterwards.

The checks behind this are in docs/verification.txt.

Skills & tools

Amazon VPC, Subnets, CIDR, Terraform, Infrastructure as Code, boto3, moto (AWS mock), VPC peering, Route tables, Amazon EC2, Terraform for_each

What I built

  • main.tf: for_each over two VPCs (subnet, IGW, route table, SG, instance) plus an auto-accepted peering connection, with peer routes in both directions.
  • checks.py: verifies the peering is active, routes run both ways, and instances sit in the right CIDRs.

How to run

pip install -r requirements-dev.txt   # moto (local AWS mock) + boto3
./local-test.sh                       # terraform apply against the mock, run checks.py, then destroy

# Real AWS (costs money; use your own IAM user/profile):
terraform init && terraform apply      # mock_endpoint defaults to "" = real AWS
terraform destroy                      # clean up when done

Verification

I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.

PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh

Real AWS deployment (2026-12-02)

I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-vpc-peering so I could prove nothing was left behind.

How I ran it: ./real-aws-run.sh (in this repo) does terraform init/apply with my AWS profile, runs checks.py against the real account, runs real-extra.sh for the live tests, and then always runs terraform destroy, even if a step fails. To get onto the instances I used EC2 Instance Connect with a throwaway SSH key that is only valid for 60 seconds. No key pairs were created in AWS and no keys were saved.

Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):

$ python3 checks.py   (against the real account)
ALL 6 CHECKS PASSED
$ ./real-extra.sh
--- peering connection status
active  10.1.0.0/16 10.2.0.0/16
--- from VPC 1 instance: ping VPC 2 instance private IP 10.2.0.181
ip-10-1-0-133.ec2.internal
4 packets transmitted, 4 received, 0% packet loss, time 3107ms
rtt min/avg/max/mdev = 0.288/0.773/2.053/0.741 ms

Teardown

Resources were up from 19:30 to 19:32 CST on 2026-12-02, then destroyed and verified gone:

=== TEARDOWN 2026-12-02 19:31 CST ===
$ terraform destroy -auto-approve -input=false -no-color -var ami_id=ami-000d209a4fc9822c4 -var project_tag=nextwork-vpc-peering
Destroy complete! Resources: 15 destroyed.
$ terraform state list   (should be empty)
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=nextwork-vpc-peering
$ live EC2 instances / volumes / VPCs tagged Project=nextwork-vpc-peering (should be empty)
=== teardown verified 19:32 CST ===

Cost

Estimated cost of the real run: about $0.01 (two t2.micro instances for about 2 minutes; peering itself is free within an AZ for this tiny amount of traffic). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.


Original project: https://nextwork.ai/projects/fd75209e-d2a1-5bdd-90e8-bdb9ee49de16 ยท Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh

Success! The configuration is valid.

Apply complete! Resources: 15 added, 0 changed, 0 destroyed.
instance_private_ips = {
  "1" = "10.1.0.4"
  "2" = "10.2.0.4"
}
peering_id = "pcx-36cdb533c8fcd3b56"
subnet_ids = {
  "1" = "subnet-82a49792abf28a9af"
  "2" = "subnet-ef54ef018c60889fc"
}
vpc_ids = {
  "1" = "vpc-1d669fff0704de856"
  "2" = "vpc-0705a399999090d69"
}
PASS: peering connection is active (active)
PASS: peering links VPC 1 and VPC 2
PASS: VPC 1 routes 10.2.0.0/16 via the peering connection
PASS: VPC 2 routes 10.1.0.0/16 via the peering connection
PASS: instance 1 IP is inside VPC 1
PASS: instance 2 IP is inside VPC 2
ALL 6 CHECKS PASSED

[exit code 0]