Simplifying VPC Peering with Terraform

Sudheera Dulan Abeysekara

Automation Engineer
Security Engineer
DevOps Engineer
AWS VPC
Docker
Terraform

TL;DR

clone the above
edit vars.tfvars
run the commands, you’re done
Hey tech wizards! 🧙‍♂️ Ever wanted to connect two VPCs seamlessly? Look no further! This Terraform script is your go-to spell for creating a magical peering connection between two virtual realms.

The Spellbook

Players on the Stage

data "aws_caller_identity" "peer": Meet the peer. We're grabbing its identity details, setting the stage for our mystical connection.
resource "aws_vpc_peering_connection" "peer": The main act. We're weaving the connection, specifying the main VPC, the peer VPC, and other details. Tags act like name tags for our peering connection, keeping everything neatly labeled.
resource "aws_vpc_peering_connection_accepter" "peer": The gracious accepter on the other side. This player automatically nods to the peering connection. No need for manual approvals here!
resource "aws_route" "main_r" and resource "aws_route" "peer_r": Think of these as the traffic conductors. We're setting up routes in the route tables of both VPCs to guide the virtual traffic. It's like placing road signs for data.

The Dance Steps

**Requester's Moves: **We kick off the peering connection with the requester side. We're setting up the connection, specifying who we want to peer with, and tagging it as the "Requester" side.
Accepter's Groove: The accepter side gracefully accepts the connection, all automated. Tags say it's the "Accepter" side.
Routing Rhythms: We create routes in both VPCs to ensure data knows where to go. Think of it as programming the GPS for our virtual traffic.

The Magic Words

Just chant these words in your terminal, and watch the magic unfold in your AWS console!

Important Notes

This script is your key to regional connections between VPCs. But remember, the magic words come with a note:
Note: After the spell is cast, make sure to enable DNS resolving on both sides for the full enchantment.
Happy peering, SD
Partner With Sudheera Dulan
View Services

More Projects by Sudheera Dulan