Overview
This example demonstrates the simplest VPC configuration with basic public and private subnets. It’s ideal for development environments or when you’re just getting started with AWS networking.This basic configuration uses a single NAT Gateway shared across all availability zones to minimize costs. For production environments, consider using multiple NAT Gateways for high availability.
What Gets Created
VPC with DNS support
A VPC with CIDR block
10.0.0.0/16 and DNS hostnames enabled for internal name resolution.Public subnets across 2 AZs
Two public subnets (
10.0.1.0/24 and 10.0.2.0/24) with Internet Gateway access for resources that need public internet connectivity.Private subnets across 2 AZs
Two private subnets (
10.0.101.0/24 and 10.0.102.0/24) with NAT Gateway for outbound internet access while keeping resources private.Complete Configuration
Key Configuration Choices
Single NAT Gateway
This example usessingle_nat_gateway = true to provision only one NAT Gateway. This reduces costs significantly but creates a single point of failure. If the availability zone hosting the NAT Gateway experiences an outage, private subnets in other AZs will lose internet connectivity.
CIDR Block Design
The/16 CIDR block provides 65,536 IP addresses, with public subnets in the 10.0.1.0/24 - 10.0.50.0/24 range and private subnets starting at 10.0.101.0/24. This leaves room for expansion.
DNS Configuration
Bothenable_dns_hostnames and enable_dns_support are enabled to allow EC2 instances to resolve each other by DNS names within the VPC.
Using the Outputs
After applying this configuration, you can reference the VPC resources in other Terraform configurations:Cost Considerations
This configuration will incur charges for:- 1 NAT Gateway (~$32/month + data processing)
- 1 Elastic IP (~$3.60/month when not associated)