TECHNOLOGIESTieInn Technologies

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 → fmt and validate → plan in CI, posted on the pull request → review → merge → apply from 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.hcl file.

Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    Many copies, environments and the team workflow

  1. Question 1easy

    How do you create a Pub/Sub topic only when var.enable_events is true?

  2. Many copies, environments and the team workflow

  3. Question 2medium

    What is the address of the raw copy of google_bigquery_dataset.layers created with for_each = toset(["raw", "staging"])?

  4. Many copies, environments and the team workflow

  5. Question 3medium

    You write for_each = ["raw", "staging"] and get an error. What's the fix?

  6. Many copies, environments and the team workflow

  7. Question 4hard

    Datasets are created with count over ["raw", "staging", "marts"]. You remove "raw" from the list. What does the plan do?

  8. Many copies, environments and the team workflow

  9. Question 5medium

    Which setting makes any plan that would delete the data lake bucket fail?

8 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.