Week 14: Terraform — Infrastructure as Code at Scale
Theme: Write modular, reusable Terraform for cloud infrastructure.
Learning Objectives
- Write Terraform modules with inputs, outputs, and version constraints
- Manage Terraform state with remote backends (S3 + DynamoDB)
- Implement Terraform workspaces for dev/staging/prod environments
- Use Terragrunt for DRY infrastructure configuration
Reading Materials
- Terraform Language Basics
- Terraform AWS Provider Docs
- Terraform Modules
- Terraform State Management
- Terraform Best Practices
- Terragrunt Documentation
- Terraform for Kubernetes
Finger Exercises (choose 2)
- Write a Terraform module for an EKS cluster: VPC, subnets, EKS control plane, node group. Use remote state with S3 backend.
- Use Terraform to create an ElastiCache Redis cluster. Output the endpoint. Import it into the K8s app as an environment variable.
- Set up a remote state S3 bucket with DynamoDB state locking.
Project
Write Terraform modules for the Phase 1-3 stack's cloud infrastructure:
modules/networking: VPC, public/private subnets, NAT gateway, security groupsmodules/eks: EKS cluster + managed node groupsmodules/rds: PostgreSQL RDS instance (for future weeks)modules/redis: ElastiCache Redis clustermodules/monitoring: Prometheus/Grafana workspace (AMP/AMG)
Create 3 workspaces: dev, staging, prod with different instance sizes. Use Terragrunt to avoid repeating configuration across environments. Integrate with the Kubernetes provider to manage K8s resources within Terraform (optional). Store state in S3 (dev) and S3 + DynamoDB locking (staging, prod).
Time Budget
| Activity | Time |
|---|---|
| Reading | 1.5 hrs |
| Finger exercises | 2 hrs |
| Project | 2.5 hrs |
| Total | 6 hrs |