QUICK START:PatternsErrors & FixesSecurityBenchmarksDevOps RecipesCheatsheetsInterviewCompareTopicsHTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsLinux & UbuntuKotlinSwiftC# / .NETJavaGoRustC++DSASystem DesignDevOpsCybersecurityAI / ML
IntermediateCI/CD & Automation

Production Terraform: Multi-AZ AWS VPC

Create the foundational network infrastructure for secure AWS deployments. This recipe builds isolated network tiers utilizing Infrastructure as Code best practices.

TerraformAWS

Prerequisites

  • AWS Credentials configured
  • Terraform installed

Configuration Files

main.tf./main.tf
module "vpc" {\n  source = "terraform-aws-modules/vpc/aws"\n  name   = "production-vpc"\n  cidr   = "10.0.0.0/16"\n  azs    = ["us-east-1a", "us-east-1b"]\n  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]\n  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]\n  enable_nat_gateway = true\n  single_nat_gateway = false\n}
Explanation:Uses the official AWS VPC module to provision subnets across Availability Zones with dedicated NAT Gateways for outbound internet access.

Verification Steps

1

Generates the execution plan without applying changes.

$terraform plan
Expected OutputPlan: 24 to add, 0 to change, 0 to destroy.

Production Gotchas

  • Setting single_nat_gateway=false deploys a NAT Gateway per AZ, which ensures high availability but incurs significant AWS hourly costs.

Frequently Asked Questions

Why use private subnets?

To protect databases and application servers from direct internet access while still allowing outbound requests via NAT.