Lab 13: Terraform IaC¶
| Field | Value |
|---|---|
| Tier | 3 — Operations |
| Estimated Time | 60 minutes |
| Prerequisites | Terraform, Docker |
| Auto-Grade | Yes |
Scenario¶
Your infrastructure team has been provisioning resources manually through cloud consoles. There is no version control, no reproducibility, and no audit trail. Last quarter, someone accidentally deleted a production database because they clicked the wrong button in the AWS console. The VP of Engineering has mandated infrastructure-as-code for all new resources.
You are starting with a local exercise using Terraform's Docker provider. You need to create a reusable module that provisions a Docker network and three containers (web, API, database) with proper configuration. The infrastructure must be fully described in Terraform code, use variables for customization, output useful values, and manage state correctly.
Objectives¶
- Initialize a Terraform project with the Docker provider
- Create a module
app-stackthat provisions a Docker network + 3 containers - Use variables for image tags, container names, and network name
- Define outputs for container IDs and network ID
- Run
terraform plansuccessfully with no errors - Run
terraform applyto create all resources - Verify all three containers are running
Setup¶
Creates a Terraform project skeleton at /tmp/lab-terraform/.
Hints¶
Hint 1: Docker provider
Hint 2: Module structure
Create `modules/app-stack/` with `main.tf`, `variables.tf`, and `outputs.tf`. Call it from the root module with `module "stack" { source = "./modules/app-stack" }`.Hint 4: Docker container resource
Hint 5: State management
For this lab, local state is fine. The state file `terraform.tfstate` is created automatically. Never commit state files to git.Grading¶
Solution¶
See the solution/ directory for complete Terraform configuration.