You have just heard about Terraform and you want to understand what it is in practice. The shell scripts you use today work, but they have no memory: running the script twice creates the resource twice, or fails. Every environment ends up drifting away from the others.
Terraform is an Infrastructure as Code (IaC) tool: you describe the wanted state of your infrastructure (virtual machines, networks, DNS) in files, and Terraform creates, changes or deletes whatever is needed to reach it. Before each change, it compares that wanted state with the real infrastructure and applies only the difference. It works in the cloud as well as on your own servers, wherever a provider exists: a plugin that talks to the API of the target technology. The file where Terraform records what it has created (the state) and the preview of the changes (the plan) are introduced further down.
What you will learn
- What Terraform is: a simple definition and its place in the DevOps ecosystem
- Which problem it solves: why scripts and clicking around are no longer enough
- What it does and does not do: the scope of the tool and the limits to know
- The key concepts: provider, resource, state, plan, the four pillars
- When to choose Terraform: a comparison with shell scripts
Why does Terraform exist?
Before IaC tools, creating an infrastructure looked like this:
- Log in to the cloud console.
- Click to create a VM, configure the network, attach a disk.
- Document the steps and hope your colleague follows the same process.
- Start over for each environment (dev, staging, prod).
The result: environments that drift apart, human errors, and infrastructures that cannot be faithfully recreated.
Terraform solves these problems by making the infrastructure declarative (you describe the result you want, not the steps to get there), versionable (the files go into Git) and idempotent.
What does Terraform do?
The diagram follows one change from end to end: the developer describes the wanted state in HCL files (the configuration language of Terraform), Terraform applies it to the infrastructure, then the state, the state file, keeps the correspondence between the code and the real world.
Terraform handles the complete lifecycle of an infrastructure:
- Create: provision new resources (VMs, networks, DNS...).
- Change: update existing resources by changing their configuration.
- Destroy: delete resources in a controlled way.
- Plan: show the planned changes before applying them.
- Remember the state: keep the correspondence between your code and the real infrastructure in a state file.
What does Terraform not do?
Terraform does not replace:
- Ansible: for configuring servers after provisioning.
- Kubernetes: for orchestrating containers.
- Docker: for building images.
- CI/CD: for deploying applications.
It integrates with all of these tools but is not meant to replace them.
What are the key concepts?
Terraform rests on four fundamental concepts:
| Concept | Short definition |
|---|---|
| Provider | Plugin that connects Terraform to an API (AWS, libvirt, Kubernetes...) |
| Resource | Object managed by Terraform (a VM, a network, a bucket...) |
| State | File that maps the real resources to the configuration |
| Plan | Preview of the changes before they are applied |
The Terraform workflow shows the plan and the state in action. The page Providers, resources and data sources details the first two concepts.
What can you manage with Terraform?
- Libvirt/KVM: create local VMs, virtual networks, disk volumes.
- AWS: provision EC2 instances, VPCs, S3 buckets, RDS databases.
- Kubernetes: deploy namespaces,
ConfigMapobjects,Serviceobjects. - GitHub: manage repositories, teams, branch protection rules.
- DNS: create DNS records at Cloudflare, OVH, or Route 53.
A single tool covers all these cases: the providers are found on the Terraform Registry.
Terraform vs shell scripts
A shell script is enough to start automating an infrastructure. The table shows what it does not do on its own.
| Criterion | Shell script | Terraform |
|---|---|---|
| Reproducible | Rarely | Yes, with pinned Terraform and provider versions |
| Idempotent | Has to be implemented by hand | Built in |
| Change detection | No | Yes (plan) |
| Built-in destroy | No | Yes |
| Dependency management | Manual | Automatic |
| Tracking the state of resources | No | Through the state |
A shell script that creates a VM does not know whether it already exists, unless you write that test yourself. Terraform knows, thanks to the state. A script stays suitable for a one-off task. Terraform becomes useful as soon as you have to recreate, change or destroy the same infrastructure several times.
A short history of Terraform
| Year | Event |
|---|---|
| 2014 | First public release by HashiCorp |
| 2017 | Terraform 0.10: providers split out |
| 2021 | Terraform 1.0: v1.x compatibility promise (language, CLI workflow, provider protocol) |
| 2023 | License change (BSL 1.1) → creation of OpenTofu |
| 2024 | Terraform 1.8: provider functions |
| 2026 | Terraform 1.17: current stable branch |
Put it into practice
This lab needs Terraform: install it first with the lesson Install Terraform, then start the lab. It works on a purely local configuration. You apply the same configuration twice to see that the second apply changes nothing. You then change a resource outside Terraform: this gap with the code is called drift, and the plan detects it. Finally you read the state to see that it keeps the memory of what Terraform has created.
Key takeaways
- Terraform describes the wanted infrastructure in
.tffiles. - It plans the changes, applies them, and remembers the resulting state.
- It does not configure the inside of servers: prefer Ansible, cloud-init or Packer for that.
- A provider connects Terraform to each technology (libvirt, AWS, GCP...).
- The state is the file that maps your code to the real infrastructure.