Hardcoding values directly into Terraform resource blocks is the quickest path to an unmaintainable configuration. When the instance type changes, the region shifts, or the same infrastructure needs to be deployed to three environments with different sizing, every hardcoded value becomes a manual edit risk — a missed change breaks the deployment, an inconsistency between environment configs creates drift. Terraform's variable system solves this through three complementary mechanisms: input variables (parameterise the configuration so callers can supply environment-specific values), output values (expose infrastructure details like IP addresses and ARNs to callers and downstream configurations), and local values (name intermediate computations and reduce repetition within a configuration). Together, these three mechanisms transform a rigid, single-environment configuration into a reusable, parameterisable infrastructure template.
30 minintermediate
Variables, Outputs and Locals
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 9 of 24
0% complete