Hands-on project
Combine Days 1–4:
Modules (VPC / EC2 / S3)
↓
Remote state (S3)
↓
Conditionals + functions + loops
↓
Workspaces (dev / prod)
↓
Optional: secrets from Vault
Assignment 1 — Vault secret
- Run Vault in
-devmode - Enable AppRole and KV v2
- Store a secret (for example
key_name) - Read it in Terraform with
data.vault_kv_secret_v2 - Launch an EC2 instance using that value
Assignment 2 — Loops
Using count and/or for_each, create:
- 3 S3 buckets
- 2 EC2 instances
Prefer for_each with meaningful keys where possible.
Assignment 3 — Conditionals
Parameterize instance type (or monitoring) with:
var.environment == "prod" ? "t3.medium" : "t3.micro"Prove dev and prod values produce different plans.
Assignment 4 — Workspaces
terraform workspace new dev
terraform workspace new prodDeploy separate infrastructure in each workspace and confirm both exist.
Clean up
terraform destroy
# stop the Vault -dev process when finishedDay 4 summary
Secrets management
↓
HashiCorp Vault + AppRole
↓
Terraform Vault provider
↓
Conditionals / functions / loops
↓
init → plan → apply (+ auto-approve in CI)