Many copies, environments and the team workflow
Terraform · 13 questions
Short notes
Key idea
Real teams run several copies of the same infrastructure (dev, staging, prod) and change them through review, not from laptops. Keep environments separate in state, identical in code, and different only in inputs.
Syntax
- Folder per environment:
envs/dev/main.tf,envs/prod/main.tf, each calling the same modules with their own backend prefix and tfvars. Clear and safe. - Workspaces:
terraform workspace new dev; one config, separate states. Simpler, easier to apply to the wrong one. - Workflow: branch →
fmtandvalidate→planin CI, posted on the pull request → review → merge →applyfrom CI.
Example
A pull request changes a bucket's lifecycle rule. CI runs terraform plan for dev and prod and comments the diff. After review, merge applies to dev automatically; prod applies after a manual approval.
Traps
- Applying from a laptop skips review and leaves no record.
- Shared state across environments means one mistake hits prod.
- Drifted environments: if prod has hand-made changes, dev tests prove nothing.
- Different provider versions per machine; commit the
.terraform.lock.hclfile.
Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →
- Question 1easy
How do you create a Pub/Sub topic only when
var.enable_eventsis true? - Question 2medium
What is the address of the
rawcopy ofgoogle_bigquery_dataset.layerscreated withfor_each = toset(["raw", "staging"])? - Question 3medium
You write
for_each = ["raw", "staging"]and get an error. What's the fix? - Question 4hard
Datasets are created with
countover["raw", "staging", "marts"]. You remove "raw" from the list. What does the plan do? - Question 5medium
Which setting makes any plan that would delete the data lake bucket fail?
Many copies, environments and the team workflow
Many copies, environments and the team workflow
Many copies, environments and the team workflow
Many copies, environments and the team workflow
Many copies, environments and the team workflow
8 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.