---
name: terraform-aws-vpc-designer
description: "Produces a secure multi-AZ AWS VPC in Terraform: subnets laid out per zone, route tables and NAT sized to your budget, and a plan-ready module with variables and outputs instead of hardcoded values. Use when an AWS VPC with public and private subnets across several availability zones needs writing in Terraform with the NAT and routing decided. Do not use for EKS clusters, security group rules for application tiers, or VPCs on GCP and Azure. Related topics: coding, devops, terraform."
---

# Terraform AWS VPC Designer

Produces a secure multi-AZ AWS VPC in Terraform: subnets laid out per zone, route tables and NAT sized to your budget, and a plan-ready module with variables and outputs instead of hardcoded values.

## When to use

Use this skill when an AWS VPC with public and private subnets across several availability zones needs writing in Terraform with the NAT and routing decided. Do not use it for EKS clusters, security group rules for application tiers, or VPCs on GCP and Azure.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Split the CIDR with cidrsubnet into one subnet per tier per AZ with spare space, and present the layout as a table.
3. Write the VPC, subnets, internet gateway, and per-tier route tables so private subnets never route to the internet gateway.
4. Implement the requested NAT mode and state its availability and cost trade-off in one sentence.
5. Structure the result as a module with validated variables, outputs for VPC and subnet IDs, and a pinned provider version.
6. Add each requested extra as an optional resource behind a variable, and summarise the monthly cost drivers.

## Inputs

- **VPC name** (free text, e.g. "dev-vpc")
- **CIDR block** (choose one: 10.0.0.0/16, 172.16.0.0/16, 192.168.0.0/16)
- **Number of availability zones** (number from 2 to 4)
- **Private subnets** (choose one: Yes, No)
- **Public subnets** (choose one: Yes, No)
- **NAT gateway** (choose one: Single NAT, One per AZ, None)
- **Environment** (choose one: dev, staging, production)
- **Extras** (choose any: VPC flow logs, S3 and DynamoDB gateway endpoints, Database subnet tier, IPv6)

## Output

Four Terraform code blocks (versions.tf, variables.tf, main.tf, outputs.tf), a subnet layout table, and a three-line cost note.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Terraform AWS VPC Designer

Design the VPC below as production-ready Terraform.

- VPC name: {{VPC name}}
- CIDR block: {{CIDR block}}
- Number of availability zones: {{Number of availability zones}}
- Private subnets: {{Private subnets}}
- Public subnets: {{Public subnets}}
- NAT gateway: {{NAT gateway}}
- Environment: {{Environment}}
- Extras: {{Extras}}

Plan the address space first: split the CIDR with cidrsubnet so each tier gets one subnet per AZ with room to add a tier later, and show the resulting table. Build the network with aws_vpc, aws_subnet per AZ and tier, an internet gateway for the public tier, and route tables per tier. Choose the NAT layout the user asked for and state its trade-off: one NAT is cheaper but a single point of failure, one per AZ survives a zone outage but costs per zone. Keep private subnets off the public route table and leave the default security group with no rules so nothing is reachable by accident. Tag every resource with Name and Environment.

Write it as a module: variables.tf with validated inputs (CIDR, AZ count, NAT mode), main.tf, outputs.tf exposing the VPC ID and subnet IDs per tier, and versions.tf pinning the AWS provider major version. Use data.aws_availability_zones so the config works in any region. Add the requested extras as optional resources controlled by a variable.

### Output
Return the Terraform files in separate code blocks (versions.tf, variables.tf, main.tf, outputs.tf), a subnet layout table, and three lines on cost: the NAT choice, flow logs, and endpoints.

## Pitfalls

- Hardcoding availability zone names, which breaks the module the first time it is applied in another region.
- Giving private subnets a route to the internet gateway, which quietly makes them public.
- Choosing one NAT gateway for production without saying that a zone outage then takes down egress for every AZ.
