Every infrastructure system needs multiple environments: at minimum, a development environment where changes are tested safely and a production environment where the live system runs. The challenge is managing these environments without duplicating the entire Terraform codebase — maintaining two separate configurations that differ only in resource sizes and names creates two codebases to update for every change, two places for bugs to hide, and two configurations that gradually diverge from each other. Terraform offers two approaches to environment management: Workspaces, which create separate state files for the same configuration within a single backend, and the directory-per-environment pattern, which maintains separate root modules with separate configurations and state files. Understanding when to use each — and the significant limitations of workspaces — is essential for managing infrastructure at scale.
30 minintermediate
Workspaces and Environment Separation
Analogy🏏Cricket
🏏 Think of it like cricket: Before standardised cricket rulebooks existed, every ground played by its own local customs — different LBW interpretations, different wide-ball rules, inconsistent DRS protocols. A touring team playing in a new city had to learn an entirely different set of rules. The standardised ICC rulebook is IaC: a version-controlled document that specifies exactly how cricket is played anywhere in the world. When any ground host asks 'how should this match be set up?', they apply the rulebook — not their memory, not local tradition, not a wiki page from 2019. Every ground becomes reproducible because they're all applying the same version-controlled specification. The insight is that codifying rules enables consistency at scale — you can run a thousand simultaneous cricket matches and every one follows the same rules because they all reference the same canonical document.
Lesson 18 of 24
0% complete