Demonstrations
These step-by-step demonstrations walk you through complete workflows using the vpc module. Each demonstration includes prerequisites, detailed instructions, and verification steps.
Getting Started
To follow any demonstration, ensure you have:
- Prerequisites met:
Terraform >= 1.0, AWS CLI configured - Authenticate with the registry:
terraform login registry.patterneddesigns.ca - Clone the demonstration repository:
git clone <demo-repo-url> - Follow the step-by-step instructions below
Step-by-Step Guides
Deploy a production-ready VPC across multiple availability zones
Step 1: Create the VPC
module "vpc" {
source = "registry.patterneddesigns.ca/patterneddesigns/vpc/aws"
version = "1.2.0"
vpc_cidr = "10.0.0.0/16"
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
enable_nat_gateway = true
single_nat_gateway = false
}
Step 2: Deploy Resources
Add EC2 instances, RDS, and other resources to the subnets.
Step 3: Verify Connectivity
Test internet access from private subnets via NAT Gateway.
Configure VPC peering between two VPCs for private connectivity
Prerequisites
- AWS account with appropriate permissions
- Terraform >= 1.0
- Two VPCs in the same or different regions
Step 1: Create the Primary VPC
module "vpc_primary" {
source = "registry.patterneddesigns.ca/patterneddesigns/vpc/aws"
version = "1.2.0"
vpc_cidr = "10.0.0.0/16"
availability_zones = ["us-east-1a", "us-east-1b"]
enable_nat_gateway = true
single_nat_gateway = true
tags = {
Name = "primary-vpc"
Environment = "production"
}
}
Step 2: Create the Secondary VPC
module "vpc_secondary" {
source = "registry.patterneddesigns.ca/patterneddesigns/vpc/aws"
version = "1.2.0"
vpc_cidr = "10.1.0.0/16"
availability_zones = ["us-east-1a", "us-east-1b"]
enable_nat_gateway = true
single_nat_gateway = true
tags = {
Name = "secondary-vpc"
Environment = "production"
}
}
Step 3: Create the Peering Connection
resource "aws_vpc_peering_connection" "primary_to_secondary" {
vpc_id = module.vpc_primary.vpc_id
peer_vpc_id = module.vpc_secondary.vpc_id
auto_accept = true
accepter {
allow_remote_vpc_dns_resolution = true
}
requester {
allow_remote_vpc_dns_resolution = true
}
tags = {
Name = "primary-to-secondary-peering"
}
}
Step 4: Update Route Tables
Add routes in each VPC to enable traffic flow through the peering connection.
# Route from primary to secondary
resource "aws_route" "primary_to_secondary" {
count = length(module.vpc_primary.private_subnet_ids)
route_table_id = element(data.aws_route_table.primary_private.*.id, count.index)
destination_cidr_block = module.vpc_secondary.vpc_cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.primary_to_secondary.id
}
# Route from secondary to primary
resource "aws_route" "secondary_to_primary" {
count = length(module.vpc_secondary.private_subnet_ids)
route_table_id = element(data.aws_route_table.secondary_private.*.id, count.index)
destination_cidr_block = module.vpc_primary.vpc_cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.primary_to_secondary.id
}
Step 5: Verify Connectivity
Test connectivity between resources in both VPCs using their private IP addresses.