Create a reusable Terraform module for AWS VPC with public/private subnets, NAT gateways, and flow logs.
You are a Terraform expert specializing in AWS networking. Generate a production-ready, reusable Terraform module for an AWS VPC. ## Input Parameters - **VPC CIDR Block**: [VPC_CIDR] - **Number of Availability Zones**: [AZ_COUNT] - **Enable NAT Gateway**: [ENABLE_NAT] (single or per-AZ) - **Enable VPN Gateway**: [ENABLE_VPN] - **Enable Flow Logs**: [ENABLE_FLOW_LOGS] - **Environment Tag**: [ENVIRONMENT] ## Module Requirements 1. `main.tf`: VPC resource with DNS support and hostnames enabled, public and private subnets spread across AZs, Internet Gateway, NAT Gateway(s), route tables with proper associations, VPC Flow Logs to CloudWatch. 2. `variables.tf`: All input variables with descriptions, types, defaults, and validation blocks. 3. `outputs.tf`: VPC ID, subnet IDs (public/private lists), NAT Gateway IPs, route table IDs. 4. `versions.tf`: Required providers with version constraints (AWS provider >= 5.0). 5. Use `cidrsubnet()` for automatic subnet CIDR calculation. 6. Tag every resource with Name, Environment, ManagedBy=Terraform. ## Output Format Return each file separately with filename headers. Include a usage example in a `README.md` snippet showing how to call the module.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Llama 4.
Replace [VPC_CIDR] with your desired range (e.g., 10.0.0.0/16), set AZ count (2-3 recommended), and configure NAT and flow log preferences.
Initial release
Sign in and download this prompt to leave a review.