Declarative vs Imperative Provisioning
What You'll Learn
You'll understand the fundamental difference between declaring what you want (declarative) versus specifying how to build it (imperative) when provisioning infrastructure.
Two Philosophies for Provisioning
When provisioning infrastructure through code, you face a choice in how to express your intent:
Imperative provisioning is like giving step-by-step cooking instructions: "First, preheat the oven to 350°F. Then, mix flour and sugar. Next, add eggs..." You explicitly define the sequence of actions to reach your goal. Each command builds on the previous state.
Declarative provisioning is like ordering from a menu: "I want lasagna." You describe the desired end state, and the system figures out how to get there. You don't care about the kitchen's internal steps—you just want lasagna on your plate.
In Practice
With imperative provisioning, you write commands that execute in order:
- "Create a virtual machine"
- "Install nginx"
- "Configure firewall rules"
- "Start the service"
If step 2 fails, you're in an inconsistent state. Re-running the script might try to create the VM again (already exists!) causing errors.
With declarative provisioning, you define:
- "There should exist a VM with these specifications"
- "nginx should be running with this configuration"
- "These firewall rules should be active"
The provisioning tool compares your declaration against the current state and makes only the necessary changes. This is the foundation of idempotency—running it multiple times produces the same result.
The Practical Difference
Imperative gives you precise control but requires you to handle all edge cases. Declarative abstracts complexity but requires trusting the tool's intelligence to converge toward your desired state.
Key Takeaway: Declarative provisioning describes what infrastructure should exist, while imperative provisioning specifies how to create it step-by-step—declarative approaches naturally support idempotency and reduce configuration drift.