The Same Server Built Three Different Ways
The simple idea: a console records the result, a script records a sequence of actions, and infrastructure as code records the desired result. For a small example, the desired result might be “one text file named welcome.txt containing Hello.” Terraform can compare that declaration with the file on disk and show the proposed action before making it. The example is intentionally local; the same workflow later applies to cloud resources, where mistakes can cost money.
A small team needs one web server, a firewall rule that allows HTTPS, and a DNS record that points a name at it. The task is ordinary, which is exactly why it is useful: almost every infrastructure problem later in this series is a larger version of it.
They build it three times.
The first time, someone works through a cloud console. They pick an image, choose an instance size, create a security group, click through the inbound rule, copy the public address, and paste it into the DNS provider. It works. Six weeks later the server needs to be rebuilt in a second region. Nobody remembers which image was selected, whether the rule was added before or after the instance, or why the disk has a non-default size. The console still shows the result, but not the decisions that produced it.
The second time, they write a shell script: create the instance, wait for it, look up its address, create the record. The script is better than memory. But it is a sequence of steps, and sequences do not handle interruptions gracefully. If the script fails after creating the instance but before creating the record, running it again creates a second instance. The script knows what it was told to do, not what already exists.
The third time, they write a configuration file and let a tool compare it with reality. The file says there should be one server with this image, this size, this firewall rule and this DNS record. The tool reads what exists, proposes the difference, and only then makes a change. Re-running it with no edits produces no new work. Changing the image produces a specific proposal: replace the server, keep the firewall rule, update the record if its value depends on the server.
That third approach is infrastructure as code (IaC): infrastructure described in versioned files, changed through a reviewable plan, and kept in a record that maps each declared object to the real one.
Figure 1 contrasts the three paths. The important difference is not "graphical versus text". It is whether the tool can tell you what it will change before it changes it, and whether it can tell you what already exists.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
T["Same outcome: one server, one HTTPS rule, one DNS record"] --> C["Console clicks"]
T --> S["Imperative script"]
T --> I["Versioned desired state"]
C --> C1["Result exists"]
C1 --> C2["Why it exists is undocumented"]
C2 --> C3["Rebuild becomes archaeology"]
S --> S1["Steps run in order"]
S1 --> S2{"Failure before the last step?"}
S2 -->|"yes"| S3["Rerun repeats work or creates duplicates"]
S2 -->|"no"| S4["Result exists, but no plan"]
I --> I1["Tool reads configuration and state"]
I1 --> I2["Plan shows the exact difference"]
I2 --> I3{"Approve?"}
I3 -->|"yes"| I4["Provider applies only that difference"]
I3 -->|"no"| I5["Nothing changes"]
I4 --> I6["State records the new mapping"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class T,I,I1,I2,I3,I4,I6 primary;
class C,S,C1,S1 secondary;
class S2,S3,C2,C3 danger;
class S4,I5 ok;
Figure 2 shows the same comparison as three bands. The console leaves a result with no reusable description. The script leaves a sequence with no memory of the result. The desired-state path keeps configuration, plan and record as separate artifacts, which is what makes review and recovery possible.
The declaration for that server is small enough to read in a review. A compact fragment names the image lookup, the instance size, the subnet, the firewall attachment and two tags; the network, provider version and AMI data source belong in the runnable configuration, but the shape is the point. A reviewer can see the size, the network placement and the firewall attachment without opening a console. The plan adds what a diff alone cannot: whether the object exists, whether it will be created, changed or replaced, and which dependency has to happen first. The resource type and labels also become the address Terraform uses in state, which is the subject of a later article.
Desired State Is a Model of Responsibility
The phrase desired state is often explained with a thermostat. You set 21 °C; the thermostat compares the room with the setting and turns heating on or off. You do not tell it how many times to open the valve. That analogy is useful but incomplete for Terraform, because a thermostat checks continuously and Terraform does not.
Terraform is closer to a building inspector with a checklist. The inspector reads the checklist, visits the building, writes a report of the differences, and waits for approval before anyone lifts a tool. The checklist is the configuration. The report is the plan. The visit is the refresh. Approval is the apply. If nobody calls the inspector again, the building can drift without anyone noticing.
Four terms follow from that model:
- Idempotence means applying the same desired state twice has the same effect as applying it once. The second apply proposes no changes.
- Convergence means the tool moves reality toward the declaration. It does not promise that reality stays there.
- Drift is the difference between what the configuration says and what the remote object now looks like. A manual console edit, another team's automation, or a provider-side change can create it.
- Reconciliation is the act of detecting and correcting drift. In Terraform, reconciliation happens when you run a plan or apply, not on a timer.
This division of responsibility matters. Terraform owns the lifecycle of the objects declared in its state. It does not own the application running inside them, the data in a database, or a resource created by a different state file. It also does not continuously repair anything. A plan is a snapshot taken under current assumptions; if someone changes the object after the plan, the apply may fail, or may overwrite the change depending on the resource and provider.
Figure 3 separates the four pieces. The configuration is the intent. The provider is the only component allowed to touch the object. State is the record that connects an address to that object. The dashed line marks the boundary Terraform does not cross: it does not watch the object between runs.
Figure 4 makes the failure path explicit. Drift is not an error by itself. It is a fact that becomes visible on the next refresh. The dangerous case is assuming a green apply yesterday means the object is correct today.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Apply completes; state matches the object"] --> B["Someone edits the object outside Terraform"]
B --> C["Drift exists but is invisible"]
C --> D{"Does the team run a plan?"}
D -->|"no"| E["Drift persists; later changes plan against a surprise"]
D -->|"yes"| F["Refresh reads the object's current attributes"]
F --> G{"Does the difference matter?"}
G -->|"no"| H["Plan reports no changes"]
G -->|"yes"| I["Plan proposes an in-place update, replacement or deletion"]
I --> J{"Is the change intended?"}
J -->|"yes"| K["Adopt it: update configuration, then plan again"]
J -->|"no"| L["Reject it: apply the reviewed correction"]
K --> A
L --> A
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class A,F,I,J,K,L primary;
class B,C,D,G,H secondary;
class E danger;
A useful exercise: name one thing in your environment that Terraform could own, and one thing it should not. A load balancer, a DNS record and a queue are good candidates. The data inside a database, a running application deployment and a person's access review are usually better owned elsewhere. Writing that boundary down prevents the common failure where a Terraform state grows until it is too risky to change.
Provisioning, Images, Configuration and Orchestration
"IaC tool" is not one category. The tools people compare usually solve different problems, and the overlap in their documentation is smaller than the overlap in the marketing.
Four responsibilities are worth separating:
- Provisioning creates accounts, networks, compute, storage and managed services. It owns lifecycle: create, change, replace, destroy.
- Image building produces a reusable machine image or container artifact from a recipe. It owns the contents of the artifact, not the running instance.
- Configuration management converges the inside of a machine or the installed software: packages, files, services, users.
- Orchestration schedules and connects running workloads: containers, pods, service discovery, rollout and restart.
Figure 5 is the table to keep next to a tool decision. It is not a ranking. A team can use several rows at once, and often should.
| Tool | Primary responsibility | Owns | Does not do by itself |
|---|---|---|---|
| Terraform | Provisioning and lifecycle through providers | Declared objects and their state mapping | Configure software inside a running VM; continuous reconciliation |
| CloudFormation | AWS-native provisioning through stacks | Stack resources and rollback behaviour | Multi-cloud ownership; application-level configuration |
| Pulumi | Provisioning using general-purpose languages | Resources and state, with language tooling | Replace the need for a state and policy model |
| OpenStack Heat | OpenStack-native stack provisioning | Heat stack resources and dependencies | AWS, Azure or Kubernetes ownership |
| Packer | Image building from a recipe | The produced image artifact | Create the running fleet or keep it configured |
| Ansible | Agentless configuration and task execution | Host state after a playbook runs | Declarative cloud lifecycle unless a module wraps it |
| Chef / Puppet | Agent-based configuration convergence | Node configuration over time | Provision the underlying cloud account or network |
| Docker | Container packaging and runtime | Image contents and container lifecycle on a host | Multi-host scheduling or cloud provisioning |
| Kubernetes | Container orchestration and reconciliation | Pods, services and declared workload state | Provision the cluster's cloud account or network |
The table has an important column: "does not do by itself". Most tool disputes disappear when each team states which column it is responsible for. Terraform can call a provisioner that runs Ansible, but that does not make Terraform a configuration-management system. Kubernetes reconciles continuously; Terraform does not. Packer builds an image; it does not keep the running fleet at that image.
A practical combination for a small platform team is Terraform for the account, network, cluster and managed services; Packer or a container build for the artifact; Kubernetes or a configuration-management tool for the workload; and a delivery pipeline for rollout. The boundaries are visible in the repository: one directory declares infrastructure, another builds the artifact, a third deploys the workload.
HCL and YAML Are Syntax Choices, Not Capability Guarantees
HCL, YAML and JSON are ways to write a document. They do not, by themselves, decide whether a tool plans, reconciles, stores state or supports a provider. That sounds obvious, yet teams regularly choose a tool because its configuration "looks simpler", then discover that the execution model is the part they actually needed.
Terraform's native syntax is HCL. The same configuration can be expressed as .tf.json, which is useful when a generator writes it. YAML is not a native Terraform configuration format; it appears in Terraform through yamlencode, yamldecode and provider-specific values, not as a replacement for .tf files. Kubernetes uses YAML as an API document, but the behaviour comes from the API server and controllers that watch it, not from YAML itself.
Figure 6 separates the two layers. The syntax layer answers "how is the document written?" The execution layer answers "who reads it, what does it compare, and what happens next?" A tool decision that only compares the top layer is incomplete.
A useful test for any tool claim: ask what happens between runs. If the answer is "nothing", the tool is plan-based. If the answer is "a controller compares desired and actual continuously", it is reconciliation-based. Both models are legitimate. They fail when a team expects one and operates the other.
Make a Tool Decision for a Small Platform Team
A tool decision is easier to defend when it is written as a record rather than argued in a meeting. The record does not need to be long, but it should name the constraints, the options and the consequences.
Use these dimensions:
- Ownership boundary. Which objects will this tool own? Which team will be on call for them?
- Lifecycle. Does the object need create/change/replace/destroy, or is it a build artifact or a running workload?
- Provider coverage. Does the tool support the services you actually use, at the versions you can verify?
- State and recovery. Where does state live, who can read it, and how do you restore a mapping after loss?
- Team skills. Can the people on call read the configuration at 02:00 without a specialist?
- Policy and review. Can a change be reviewed, tested and blocked before it reaches production?
- Licensing and hosting. Does the licence fit the organisation, and can the control plane run where the team needs it?
- Exit cost. What does it take to move the same objects to another tool later?
Terraform and OpenTofu belong in this discussion as separate options, not as a branding argument. OpenTofu is a fork of Terraform with its own release cadence and licence; compatibility is substantial but not universal, and provider or feature differences should be checked against the versions you will actually run. The honest position is: choose one deliberately, record why, and test the migration path rather than assuming either direction is free.
Choose the automation boundary
Write a one-page decision record for a small platform team that must own a VPC, two web servers, a load balancer, a managed database and DNS.
Cover:
- Decision. One sentence naming the provisioning tool and the boundary it owns.
- Context. Team size, cloud accounts, existing skills, compliance or budget constraints.
- Options. At least three, including one non-Terraform option and one "do less with one tool" option.
- Consequences. What becomes easier, what becomes harder, what the team must operate, and how state is protected.
- Review trigger. The condition that would reopen the decision, such as a second cloud, a licensing change or a provider gap.
A strong record will say what the tool will not own. That sentence is usually the one that prevents an argument six months later.
Next in the Series
In Terraform Under the Hood: Configuration, Providers and State, we'll explore Use a runnable local example to see how modules, providers, Terraform Core and state work together.