Configuration Approach
The AWS VPC Terraform module uses a declarative configuration model through input variables. All configuration is done by setting variable values when calling the module - there are no configuration files to manage.Core Configuration Pattern
The module follows these configuration principles:- Sensible Defaults - Most variables have default values, allowing minimal configuration for simple use cases
- Explicit Enablement - Advanced features (NAT gateways, VPC endpoints) are disabled by default and must be explicitly enabled
- List-Based Subnet Definition - Subnets are defined as lists of CIDR blocks paired with availability zones
- Hierarchical Tagging - Global tags apply to all resources, with subnet-specific tags for granular control
Essential Variables
Name to be used on all resources as identifier. This becomes part of resource names (e.g.,
{name}-vpc, {name}-subnet-public-us-east-1a).Default: ""The CIDR block for the VPC. Must be a valid IPv4 CIDR block.Default:
""Example: "10.0.0.0/16"A list of availability zones in the region where subnets will be created. The module distributes subnets across these AZs.Default:
[]Example: ["us-west-2a", "us-west-2b", "us-west-2c"]Subnet Configuration Variables
A list of public subnet CIDR blocks inside the VPC. These subnets will have routes to an Internet Gateway.Default:
[]Example: ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]A list of private subnet CIDR blocks inside the VPC. These subnets can optionally route through NAT gateways.Default:
[]Example: ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]A list of database subnet CIDR blocks. Automatically creates an RDS subnet group when specified.Default:
[]Example: ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]A list of ElastiCache subnet CIDR blocks. Automatically creates an ElastiCache subnet group when specified.Default:
[]Example: ["10.0.31.0/24", "10.0.32.0/24", "10.0.33.0/24"]DNS Configuration
Enable DNS hostnames in the VPC. Set to
true if you want to use private DNS within the VPC.Default: falseUsed in: main.tf:4Enable DNS resolution in the VPC. Set to
true if you want to use private DNS within the VPC.Default: falseUsed in: main.tf:5For most production VPCs, you should enable both
enable_dns_hostnames and enable_dns_support to allow EC2 instances to resolve private DNS names.Instance Configuration
A tenancy option for instances launched into the VPC. Valid values:
default, dedicated.Default: "default"Used in: main.tf:3Automatically assign public IP addresses to instances launched in public subnets. Set to
false if you don’t want auto-assignment.Default: trueUsed in: main.tf:106Routing Configuration
A list of Virtual Private Gateway (VGW) IDs that the private route tables should propagate routes from.Default:
[]Used in: main.tf:47A list of Virtual Private Gateway (VGW) IDs that the public route table should propagate routes from.Default:
[]Used in: main.tf:22Minimal Configuration Example
Complete Configuration Example
Configuration Validation
Next Steps
Subnet Types
Learn how to configure different subnet types
NAT Gateways
Configure NAT gateways for private subnet internet access
VPC Endpoints
Set up VPC endpoints for S3 and DynamoDB
Tagging
Implement tagging strategies for your VPC resources