What Is Terraform?
You have decided Crumb's infrastructure should live in files. Now you need a tool that reads those files and talks to the cloud. Terraform is the most widely used one, and it works with hundreds of platforms, not just one cloud.
The rule
Terraform compares what you wrote with what it built, then closes the gap.
Terraform is a command-line program from HashiCorp. It is built from three parts:
- Configuration — your
.tffiles, written in HCL, describing what should exist. - State — a file (by default
terraform.tfstate) where Terraform records what it has built and the real IDs it got back, so it can match each block in your files to a real object. - Providers — plugins that know one platform's API: AWS, Azure, Google Cloud, GitHub, Cloudflare, Kubernetes and many more. Terraform itself knows no cloud; providers do the talking.
provider "aws" {
region = "ap-south-1"
}
resource "aws_s3_bucket" "assets" {
bucket = "crumb-bakery-assets"
}Here the aws provider will create one storage bucket in the Mumbai region.
Terraform has a small, fixed loop:
- Write the configuration.
- Plan —
terraform planshows exactly what would be created, changed or destroyed. - Apply —
terraform applymakes those changes and updates the state.
Since version 1.6 Terraform is released under the Business Source License; a community fork called OpenTofu keeps an open-source licence and reads the same language. What you learn here works in both.
The shortcut
Before every command, picture a three-way comparison: the files (what you want), the state (what Terraform thinks it built) and the real cloud. The plan is the difference.
Files
You add the
aws_s3_bucket.assetsblock tomain.tf.
The trap: deleting or losing the state file. Terraform then no longer knows it built the bucket and will try to create it again, which fails or duplicates things.
Drills
Answer fast — trust the rule.
What does a Terraform provider do?
Which command shows the changes without making them?
What is the state file for?
Someone deletes terraform.tfstate and runs terraform plan on an unchanged configuration. What is likely?
Remember
- Terraform = configuration + state + providers.
- Shortcut: plan is the gap between what you wrote and what state says exists.
- Trap: losing state makes Terraform forget what it owns.
