Terraform is a tool that creates and changes infrastructure from text files. You describe the servers, networks, databases, DNS records or containers you want in a language called HCL, and Terraform works out which API calls turn what exists today into what you described. The same files then become the documentation, the change history and the disaster recovery plan of your platform.
What Terraform looks like
Here is a complete Terraform configuration. It runs an nginx container on your own machine through Docker. You will run it yourself in lesson 3.
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 4.0"
}
}
}
provider "docker" {}
resource "docker_image" "web" {
name = "nginx:1.27-alpine"
}
resource "docker_container" "web" {
name = "orbit-web"
image = docker_image.web.image_id
ports {
internal = 80
external = 8080
}
}
Read it top to bottom. You ask for the Docker provider, then for an image and a container that uses it. Nothing says “pull the image first” or “start the container”. Terraform sees that the container refers to docker_image.web and creates them in the right order. You describe what, Terraform figures out how. That is what declarative means.
The problem infrastructure as code solves
Picture the team behind Orbit two years ago. Production was built by hand in a cloud console. It worked, until it did not:
- The wiki lies. The setup page says the database has 2 vCPUs. Someone resized it during an incident and never updated the page.
- Staging is not production. Both were built by clicking, months apart. A bug that only happens in production costs a week.
- Nobody knows who changed what. A firewall rule opened “temporarily” is still open a year later, and nobody remembers why.
- The region outage. Rebuilding everything in another region means following a 40-step checklist under pressure, from memory.
- New environments take days. A developer asks for a test environment and waits for someone with console access.
Infrastructure as code (IaC) answers every one of these with the same habit software teams already have: keep it in Git.
| Benefit | What it means for Orbit |
|---|---|
| Repeatable | Staging and production come from the same files with different inputs |
| Reviewed | Every change is a pull request with a readable plan attached |
| Auditable | git log tells you who changed the firewall, when and why |
| Recoverable | A new region is terraform apply with a different variable |
| Self-documenting | The code is the description of what exists, and it cannot drift silently |
| Fast | A new environment takes minutes, not a ticket queue |
How Terraform works
Every Terraform change follows the same loop:
- Write configuration in
.tffiles. - Plan: Terraform reads the configuration, reads its state (its record of what it created before), asks the real APIs for the current situation and prints the difference as a list of creates, updates and destroys.
- Apply: after you approve the plan, Terraform makes those API calls, in parallel where it can and in dependency order where it must.
- Record: the result is saved to the state file, so the next plan starts from an accurate picture.
The pieces that make this possible:
- Providers are plugins that know how to talk to one API: AWS, Azure, Google Cloud, Kubernetes, Docker, GitHub, Cloudflare, Datadog and thousands more on the Terraform Registry.
- Resources are the objects a provider manages, such as
docker_containeroraws_s3_bucket. - The dependency graph comes from references between resources. Because the container uses
docker_image.web.image_id, Terraform knows the image comes first. - State maps each resource in your code to the real object it manages. Lesson 5 is all about it.
The plan is the safety net. terraform plan never changes anything. Reading the plan before every apply, and especially looking for the word destroy, is the single most important Terraform habit.
The vocabulary you will use every day
| Term | Meaning | Example |
|---|---|---|
| Provider | Plugin for one platform’s API | kreuzwerker/docker, hashicorp/aws |
| Resource | Something Terraform creates and manages | resource "docker_container" "web" |
| Data source | Something Terraform only reads | data "aws_caller_identity" "me" |
| Variable | Input to a configuration | variable "environment" |
| Output | Value a configuration exposes | output "url" |
| Module | A folder of .tf files you can reuse | module "cache" |
| State | Terraform’s record of what it manages | terraform.tfstate |
Terraform in 2026: what changed
If you learned Terraform a few years ago, the language looks the same but the landscape moved:
- Licence and ownership. In 2023 HashiCorp moved Terraform from the open-source MPL licence to the Business Source Licence (BSL). Using Terraform for your own infrastructure is unaffected; building a competing hosted product is restricted. IBM completed its acquisition of HashiCorp in February 2025.
- OpenTofu. The community forked the last open-source version as OpenTofu, run under the Linux Foundation. It reads the same HCL and most of this course applies to it, but the two projects now add different features.
- HCP Terraform is the new name of Terraform Cloud, HashiCorp’s hosted service for remote runs, state and policies.
- The language grew a lot. Since version 1.5:
| Version | Feature | Lesson |
|---|---|---|
| 1.5 | import blocks and config generation | 7 |
| 1.6 / 1.7 | terraform test and mock providers | 6, 14 |
| 1.7 | removed blocks, import with for_each | 5, 8 |
| 1.8 | Provider-defined functions | 9 |
| 1.10 / 1.11 | Ephemeral values, write-only arguments, S3 native locking | 4, 5, 15 |
| 1.14 | terraform query, list blocks and actions | 7, 13 |
| 1.15 | Dynamic module sources, deprecation warnings, convert() | 4, 6, 9 |
| 1.16 | import inside modules, destroy = false, Mermaid graphs | 3, 5, 6 |
| 1.17 | Terraform Policy GA, -minimal-refresh, variables in provider requirements | 3, 14, 15 |
Terraform compared with other tools
Terraform and Ansible solve different problems and are often used together. Terraform provisions: it creates the server, the network and the load balancer and remembers them in state. Ansible configures: it connects to a server that already exists and installs packages, edits files and restarts services. A common split: Terraform builds the machine, then a baked image, cloud-init or Ansible sets up what runs on it.
| Terraform | AWS CloudFormation / CDK | Pulumi | OpenTofu | |
|---|---|---|---|---|
| Clouds | Any, through providers | AWS only | Any | Any, same providers as Terraform |
| Language | HCL | YAML/JSON, or code with CDK | Python, TypeScript, Go, C#… | HCL |
| State | State file you store (or HCP Terraform) | Managed by AWS | Pulumi Cloud or your own backend | State file, with built-in encryption |
| Preview | terraform plan | Change sets | pulumi preview | tofu plan |
| Licence | BSL | Proprietary service | Apache 2.0 | MPL 2.0 |
Pick CloudFormation if you are all-in on AWS and want AWS to hold the state. Pick Pulumi if your team prefers loops and classes in a general-purpose language. Pick Terraform or OpenTofu if you manage more than one platform and want the largest ecosystem of providers, modules and people who already know it.
Do you need Terraform?
You do benefit from it as soon as infrastructure outlives one afternoon: more than one environment, more than one person making changes, anything you would need to rebuild after a disaster, or anything an auditor might ask about.
You can skip it for a one-off experiment you will delete tonight, or when a platform already manages the infrastructure for you (a PaaS, a hosted database you configure in two fields).
Quick reference
| Task | Command |
|---|---|
| Download providers and modules | terraform init |
| Format all files | terraform fmt -recursive |
| Check the configuration | terraform validate |
| Preview changes | terraform plan |
| Make the changes | terraform apply |
| Remove everything the configuration manages | terraform destroy |
| Show what is in state | terraform state list |
| Print the installed version | terraform version |
Exercise
A teammate opened a firewall port in the cloud console last month. Today you run terraform plan on code that does not mention that port. What does the plan show?
Show answer
Answer: B. Plan compares your code with the real infrastructure. A change made outside Terraform, called drift, shows up as a difference that apply would undo. Fix drift by putting the change in code or by reverting it.
Exercise
Orbit needs a new virtual machine and, on it, nginx installed with a custom config file. Which split is the usual one?
Show answer
Answer: C. Terraform is built to provision and track infrastructure. Software inside a machine is better handled by images, cloud-init or a configuration tool. Lesson 13 explains why provisioners are a last resort.
Key takeaways
- Terraform turns HCL files into API calls: you describe the result, it works out the steps.
- Infrastructure as code brings Git habits (review, history, rollback) to infrastructure.
- Every change is write, plan, apply, record. Read the plan before you approve it.
- Providers talk to APIs, resources are what you manage, state links the two.
- Terraform now ships under the BSL; OpenTofu is the open-source fork with the same language.
- Terraform provisions, Ansible configures, and the two work well together.
FAQ
What is Terraform used for?
Creating and changing infrastructure from code: cloud networks, servers, databases, Kubernetes clusters, DNS, CDN settings, monitoring dashboards, GitHub repositories and anything else with an API and a provider.
Is Terraform still free?
Yes, the Terraform CLI is free to download and use for your own infrastructure. The BSL licence only restricts offering Terraform itself as a competing commercial service. HCP Terraform has a free tier and paid plans for larger teams.
Should I learn Terraform or OpenTofu?
Learn Terraform’s language and workflow; it transfers almost completely. Use whichever one your company runs. The commands differ only in name (terraform plan versus tofu plan) for everything in the first eleven lessons of this course.
Do I need to know a cloud before learning Terraform?
Not for this course: lessons 1 to 11 use Docker on your own machine. To use Terraform at work you also need to understand the platform you manage, because Terraform does not hide what a VPC or an IAM role is.
What is the hardest part for beginners?
State. Most scary moments (lost changes, lock errors, a plan that wants to recreate everything) come from not knowing what the state file is and where it lives. Lesson 5 covers it in detail.