Terraform Tutorial — What is Terraform?

4 minute read

Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It lets you define your entire cloud infrastructure — servers, networks, databases, DNS records, monitoring, and more — in human-readable configuration files. You run a single command, and Terraform creates everything for you.


What Problem Does Terraform Solve?

Imagine you need to set up a new web application on AWS. You need:

  • A VPC with public and private subnets
  • An EC2 instance running your application
  • An S3 bucket for file storage
  • A security group allowing HTTP traffic
  • An RDS database for your backend

Doing this manually through the AWS console takes an hour, requires screenshots for documentation, and is impossible to repeat exactly. If your colleague needs the same setup in a different region, they start from scratch.

Terraform solves this. You write a configuration file describing all of these resources, run terraform apply, and everything is created in minutes. Need another copy? Run the same config in a different region. Need to tear it all down? terraform destroy.


What is Infrastructure as Code?

Infrastructure as Code (IaC) is the practice of managing infrastructure through configuration files rather than manual processes. Instead of clicking through a cloud console or running ad-hoc scripts, you write code that describes your desired infrastructure state.

Without IaC With IaC (Terraform)
Click through cloud console manually Write .tf files describing what you need
Hope you remember every step Configuration is the documentation
Impossible to reproduce exactly Same config = same infrastructure, every time
No history of changes Version control with Git — see every change
One person holds the knowledge Anyone on the team can read and modify config
Scaling means more manual work Scaling means changing a number in a file

Terraform is Declarative

Terraform uses a declarative approach. You describe WHAT you want, not HOW to create it.

Think of it like ordering at a restaurant. You say “I’d like a margherita pizza” (declarative) — you don’t walk into the kitchen and say “take 200g of dough, spread it into a circle, add 100ml of tomato sauce…” (imperative).

In Terraform, you write:

resource "aws_s3_bucket" "my_bucket" {
  bucket = "my-unique-bucket-name"

  tags = {
    Environment = "dev"
    Team        = "backend"
  }
}

Terraform figures out HOW to create the bucket. If it already exists, Terraform does nothing. If the tags are wrong, Terraform updates them. If the bucket doesn’t exist, Terraform creates it.


Idempotency — Run It Twice, Get the Same Result

Idempotency means running the same operation multiple times produces the same result as running it once.

When you run terraform apply the first time, Terraform creates your infrastructure. When you run it a second time with no config changes, Terraform says “no changes needed” and does nothing. This is a fundamental property that makes Terraform safe to run repeatedly.

$ terraform apply

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

The Blueprint Analogy

The best way to understand Terraform is the architecture blueprint analogy:

Concept Building a House Terraform
Blueprint Architectural drawings .tf configuration files
Review Architect reviews plans terraform plan (dry run)
Build Construction crew builds terraform apply (create infra)
Inspect Walk through finished house terraform show (view state)
Demolish Tear down the building terraform destroy (remove infra)
Rebuild Build from same blueprint Run apply again in a new region

Just as you wouldn’t build a house without blueprints, you shouldn’t build cloud infrastructure without IaC.


Why IaC Matters

Reproducibility

The same Terraform config creates the exact same infrastructure every time. Your staging environment is a true copy of production — not “mostly the same.”

Version Control

Terraform files live in Git. Every change is a commit. You can see who changed what, when, and why. You can revert a bad change by reverting a commit.

Collaboration

Your entire team can review infrastructure changes in pull requests, just like code reviews. No more “I changed a security group rule but forgot to tell anyone.”

Disaster Recovery

If a region goes down, you can spin up your entire infrastructure in another region by running the same Terraform config with a different region variable.

Automation

Terraform integrates into CI/CD pipelines. Merge a PR, and your infrastructure updates automatically. No human needs to log into a console.


Who Uses Terraform?

Terraform is used by organizations of all sizes:

  • Startups: Small teams managing AWS/GCP with a handful of .tf files
  • Enterprises: Large companies with hundreds of modules and Terraform Cloud
  • Platform teams: Building self-service infrastructure platforms for developers
  • SRE teams: Ensuring production infrastructure is reproducible and auditable
  • Consultancies: Deploying client infrastructure consistently across projects

What’s Next?

Now that you understand what Terraform is and why IaC matters, the next page compares Terraform to other popular tools so you can understand when to use Terraform and when another tool might be a better fit.


← Introduction Terraform vs Other Tools →