Architecture
The module creates a multi-AZ network architecture:Resources Created
VPC (Virtual Private Cloud)
- Resource:
aws_vpc.main - Isolated virtual network with DNS hostnames and support enabled
- Default CIDR:
10.0.0.0/16(65,536 IP addresses)
Public Subnets
- Resource:
aws_subnet.public - One subnet per availability zone
- Auto-assigns public IPs to instances
- Used for: Load Balancers, NAT Gateways
- Tagged for EKS Load Balancer Controller discovery
Private Subnets
- Resource:
aws_subnet.private - One subnet per availability zone
- No public IP assignment
- Used for: EKS worker nodes, RDS instances, application pods
- Tagged for EKS internal load balancers
Internet Gateway
- Resource:
aws_internet_gateway.main - Provides internet connectivity for public subnets
NAT Gateways
- Resource:
aws_nat_gateway.main - One per availability zone for high availability
- Elastic IPs (
aws_eip.nat) for static public addresses - Enables outbound internet access from private subnets
- Cost: ~$32/month per NAT Gateway + data transfer
Route Tables
-
Public Route Table:
aws_route_table.public- Routes all traffic (
0.0.0.0/0) to Internet Gateway - Shared across all public subnets
- Routes all traffic (
-
Private Route Tables:
aws_route_table.private- One per availability zone
- Routes external traffic to corresponding NAT Gateway
- Isolated failure domains
Security Groups
EKS Cluster Security Group
- Resource:
aws_security_group.eks_cluster - Ingress Rules:
- HTTPS (443) from anywhere - API server and application traffic
- HTTP (80) from anywhere - redirects to HTTPS
- All protocols from self - inter-node communication
- Egress Rules:
- All traffic to anywhere - updates, ECR, AWS APIs
RDS Security Group
- Resource:
aws_security_group.rds - Ingress Rules:
- PostgreSQL (5432) from EKS security group only
- Egress Rules:
- All traffic allowed
- Ensures database is only accessible from cluster
Variables
Deployment environment:
dev, staging, or prodAWS region for resource deployment
CIDR block for the VPC. Default provides 65,536 IP addresses.
List of availability zones to use. Determines the number of subnets and NAT gateways created.
CIDR blocks for public subnets (one per AZ). Each provides 256 IP addresses.
CIDR blocks for private subnets (one per AZ). Each provides 256 IP addresses.
Project name used for resource tagging and naming
Outputs
ID of the created VPC
CIDR block of the VPC
IDs of public subnets for Load Balancers and NAT Gateways
IDs of private subnets for EKS nodes and RDS instances
ID of the Internet Gateway
IDs of NAT Gateways (one per AZ)
ID of the security group for EKS cluster
ID of the security group for RDS instances
Usage Example
Best Practices
Multi-AZ Deployment
Deploy across multiple availability zones for high availability. If one AZ fails, services in other AZs continue operating.Private Subnet Isolation
EKS worker nodes and RDS instances run in private subnets without direct internet access. This prevents unauthorized external access while allowing outbound connectivity through NAT gateways.Cost Optimization
For development environments, consider using a single NAT Gateway instead of one per AZ:Kubernetes Integration
Subnets are automatically tagged for AWS Load Balancer Controller discovery:kubernetes.io/role/elb = 1on public subnetskubernetes.io/role/internal-elb = 1on private subnetskubernetes.io/cluster/<cluster-name> = shared
Security Considerations
Network Segmentation
Public and private subnets provide network segmentation. Application workloads in private subnets are not directly accessible from the internet.Security Group Rules
Security groups implement defense in depth:- RDS only accepts connections from EKS security group
- EKS allows HTTPS/HTTP from internet (for application access)
- All inter-node communication allowed within cluster