Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Terraform  ›  Lesson

What Is Terraform?

What is Terraform? 12 minTerraform is a declarative infrastructure as code tool that reads configuration files, compares them with a saved record of what it built, and plans and applies the difference through provider plugins.

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 .tf files, 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:

  1. Write the configuration.
  2. Plan — terraform plan shows exactly what would be created, changed or destroyed.
  3. Apply — terraform apply makes 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.

Adding Crumb's asset bucketStep 1 of 4
  1. Files

    You add the aws_s3_bucket.assets block to main.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.

quick drill

What does a Terraform provider do?

quick drill

Which command shows the changes without making them?

quick drill

What is the state file for?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTerraform in three parts

Explain to a teammate how Terraform decides what to do when you run it on Crumb's configuration. Mention the configuration, the state file and the providers, and the write, plan, apply loop.