**Overview**Design a reusable Terraform AWS VPC module that creates a VPC across N AZs, public/private subnets, optional NAT gateways, flow logs, route tables, and exports IDs consumed by downstream modules.**Module inputs (key)**- vpc_name (string)- cidr_block (string)- azs (list(string)) — length N- public_subnet_cidrs (list(string)) — optional, or auto-slice from cidr_block- private_subnet_cidrs (list(string))- enable_nat (bool, default = true)- nat_gateway_strategy (string: "one-per-az" | "single" | "none")- enable_flow_logs (bool)- flow_log_destination_arn (string, optional)- tags (map)- enable_dns_hostnames, enable_dns_support (bools)Example variable snippet:hcl
variable "azs" { type = list(string) }
variable "nat_gateway_strategy" { type = string, default = "one-per-az" }
**Resources & responsibilities**- aws_vpc, aws_subnet (public/private per AZ), aws_internet_gateway- aws_eip & aws_nat_gateway (per strategy)- aws_route_table + aws_route_table_association (public routes to IGW; private to NAT)- aws_flow_log when enabled (to CloudWatch / S3 via destination ARN)- outputs: private_subnet_ids, public_subnet_ids, route_table_ids, vpc_id, nat_gateway_idsExample outputs:hcl
output "private_subnet_ids" { value = aws_subnet.private[*].id }
output "public_subnet_ids" { value = aws_subnet.public[*].id }
output "route_table_ids" { value = concat(aws_route_table.public[*].id, aws_route_table.private[*].id) }
**Versioning strategy**- Use semantic versioning (vMAJOR.MINOR.PATCH).- Tag releases in VCS and publish module to private registry / Terraform Registry.- Backwards-incompatible changes bump MAJOR; additions/bugfixes bump MINOR/PATCH.- Maintain CHANGELOG and migration notes for MAJOR bumps.**Testing**- Unit: terraform validate, tflint, checkov.- Integration: Terratest (Go) or kitchen-terraform to deploy in a sandbox AWS account, verify expected resources, subnets per AZ, NAT behavior, flow logs exist, route tables correct.- CI pipeline: run plan in PR, run tests against ephemeral account, run policy checks.**Documentation**- README with: purpose, inputs table (required/default), outputs table, examples for common strategies (multi-AZ with single NAT vs one-per-AZ), upgrade/migration notes, testing instructions, IAM permissions required.- Provide example usage snippet and minimal example repo referencing a released module version:hcl
module "vpc" {
source = "git::ssh://git@.../modules/vpc.git?ref=v1.2.0"
vpc_name = "prod-vpc"
cidr_block = "10.0.0.0/16"
azs = ["us-east-1a","us-east-1b"]
nat_gateway_strategy = "one-per-az"
}
**Operational notes / trade-offs**- Cost vs availability: one-per-az increases cost but improves AZ isolation.- Route table design: keep separate RTs per subnet group to allow custom routing later.- Security: default flow logs optional; recommend enabling in prod.This design balances reusability, clear interface, testability, and operational guidance for team adoption.