Terraform

Terraform AWS VPC

Production-grade VPC with modular subnets, NAT, and routing.

Terraform 1.7+AWSMulti-AZOpen Source

A fully modular Terraform configuration for AWS VPC infrastructure. Provisions public and private subnets across multiple availability zones, NAT gateways, internet gateways, and route tables following AWS Well-Architected Framework guidance.

Updated 10 March 2026 Terraform

Tech Stack

Terraform~> 1.7
AWS Provider~> 5.0
Terraform CloudRemote state

Features

  • Multi-AZ public and private subnet layout
  • NAT gateway per AZ for high availability
  • VPC Flow Logs to CloudWatch
  • Configurable CIDR blocks via variables
  • Module outputs for ECS, EKS, and RDS integration

Architecture

The VPC is split into public subnets (for load balancers and NAT gateways) and private subnets (for application workloads and databases). Each AZ gets its own NAT gateway to avoid cross-AZ traffic costs during failover.

Usage

Clone the repository and copy `tfvars/example.tfvars` to `terraform.tfvars`. Set your AWS region, CIDR block, and the number of AZs. Run `terraform init && terraform plan` to preview, then `terraform apply` to provision.

Variables

Key inputs: `vpc_cidr` (default `10.0.0.0/16`), `azs` (list of availability zones), `private_subnet_count`, `enable_nat_gateway` (bool), `single_nat_gateway` (cost optimisation flag for non-prod).

File Structure

  • main.tf
  • variables.tf
  • outputs.tf
  • versions.tf
  • modules/
    • subnet/
      • main.tf
      • variables.tf
      • outputs.tf
    • nat/
      • main.tf
      • variables.tf
  • tfvars/
    • example.tfvars
    • prod.tfvars
  • .gitlab-ci.yml
  • README.md
GitLab (coming soon)