There are two fundamentally different ways to tell a computer what you want. The imperative approach says 'do this, then do that, then do this other thing' — it specifies the steps. The declarative approach says 'I want this to be the state of the world' — it specifies the outcome. Bash scripts for infrastructure are imperative: `aws ec2 run-instances --instance-type t3.medium`, then `aws ec2 create-security-group`, then `aws ec2 authorize-security-group-ingress`. Terraform is declarative: `resource "aws_instance" ... { instance_type = "t3.medium" }` — you describe the desired end state and Terraform figures out the steps. The distinction matters more than it seems: declarative configurations are inherently idempotent (applying them twice produces the same result), self-documenting (the code describes what exists, not what to do), and composable (you can combine declarative specifications without worrying about operation order). Imperative scripts are fragile: run them twice and you might create duplicate resources; run them partially and you're left in an unknown intermediate state.
30 minintermediate
Declarative vs Imperative Infrastructure
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 2 of 24
0% complete