Terraform: Declarative vs Imperative — Why It Doesn’t Click at First
When you start learning Terraform, there’s one concept you immediately run into: Declarative configuration.
Every tutorial says the same thing:
“You define the desired state of your infrastructure.”
But if you’re honest as a beginner, this explanation usually doesn’t help much. At least for me, it didn’t. I kept wondering:
- “How is this different from scripting?”
- “Isn’t this just another way to run AWS CLI commands?”
- “Why does this feel so abstract?”
The real issue is not Terraform itself. It’s the way we are introduced to it. Most learning materials start with complex topics like architecture, modules, backend setup, and state management. But for beginners, none of that matters yet. What matters first is simple: Getting something to actually work.
Imperative vs Declarative — The Real Difference
Let’s simplify the comparison.
Imperative (AWS CLI, scripts)
Think of it like “Giving step-by-step instructions to a chef.”
- Chop the onions
- Heat the pan
- Add oil
- Cook the onions
If something goes wrong, you fix each step manually or restart the process.
👉 This is process-driven thinking.
Declarative (Terraform)
Now think of it like “Showing the chef a photo of the final dish.” You don’t describe the steps; you simply say, “I want this result.” Then the system:
- Checks the current state
- Figures out what is missing
- Makes the necessary changes automatically
👉 This is state-driven thinking.
Why This Concept Doesn’t Click at First
Here’s the real reason: You cannot understand declarative systems without experiencing one. Reading about it is not enough. Terraform only makes sense when you actually see it work.
The First Configuration That Changed Everything
My understanding of Terraform didn’t come from documentation. It came from a very simple file. I ignored modules, backend configuration, and best practices, and started with just one file:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "first_server" {
ami = "ami-0c02fb55956c7d316"
instance_type = "t2.micro"
tags = {
Name = "terraform-first-server"
}
}
Run the following commands in order:
terraform init
terraform plan
terraform apply
Type yes when prompted. After a short wait, an EC2 instance is created.
The Moment It Finally Makes Sense
When this worked for the first time, something clicked. I realized I didn’t describe steps—I described a final state, and Terraform handled the rest. And that’s the key idea.
💡 Key Insight
Terraform is not a tool that executes steps. It is a system that reconciles the desired state with the actual state.
Why Declarative Thinking Feels Strange at First
Most beginners naturally think in steps: “First create EC2, then attach security group, then configure SSH.”
But Terraform flips this mindset. Instead of thinking in order, you think in outcome.
- 👉 Not “how to do it”
- 👉 But “what should exist”
Why Starting With Modules Makes Things Worse
Many tutorials introduce modules, remote state (S3 backend), and complex folder structures right away. But for beginners, this creates friction because:
- You haven’t experienced success yet.
- You don’t understand why structure matters.
- You don’t feel the problem it solves.
So you end up in this loop: “I understand the structure, but I don’t understand Terraform.”
A Better Way: Top-Down Learning
The approach that worked for me was simple: Ignore structure. Ignore best practices. Focus only on output.
Start with: “What do I want to exist?” → Write it in a single main.tf → Apply it → Observe the result. That’s it.
What Changes After Your First Success
Once you successfully create infrastructure, your mindset shifts from "Read → Confused → Stop" to "Run → Observe → Understand → Learn deeper." This shift is critical because understanding comes after experience, not before it.
🎯 Final Insight
Don’t try to understand Terraform first. Make it work first — then understanding will follow naturally.
That is the real difference between struggling and progressing quickly with infrastructure tools like Terraform.