Terraform is an infrastructure-as-code tool. Instead of clicking around in the AWS/GCP/Azure console to create servers, databases, and networks, you write code that describes what you want, and Terraform creates it for you.
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = { Name = "my-web-server" }
}
Run terraform apply, and Terraform creates an EC2 instance. Run it again β nothing happens (itβs already there). Change the instance type and run again β Terraform updates it. Delete the code and run again β Terraform destroys it.
Why infrastructure as code
Without IaC: you click through the AWS console, create 15 resources, forget what you configured, canβt reproduce it, and your coworker has no idea whatβs running.
With Terraform: your infrastructure is in Git. Itβs versioned, reviewable, reproducible, and documented. You can spin up an identical environment in minutes.
How it works
- Write
.tffiles describing your infrastructure terraform planβ shows what will change (preview)terraform applyβ creates/updates the resourcesterraform destroyβ tears everything down
Terraform tracks what it created in a state file, so it knows the difference between what exists and what you want.
Providers
Terraform works with 3,000+ providers β AWS, GCP, Azure, Cloudflare, GitHub, Datadog, Vercel, and more. Each provider gives you resources to manage:
# AWS
resource "aws_s3_bucket" "files" { bucket = "my-files" }
# Cloudflare
resource "cloudflare_record" "www" {
zone_id = "abc123"
name = "www"
value = "1.2.3.4"
type = "A"
}
Terraform vs. alternatives
| Tool | Language | Cloud support | Best for |
|---|---|---|---|
| Terraform | HCL | All clouds | Multi-cloud, most popular |
| CloudFormation | JSON/YAML | AWS only | AWS-only shops |
| Pulumi | Python/TS/Go | All clouds | Devs who prefer real languages |
| CDK | TypeScript | AWS (mainly) | AWS + TypeScript teams |
When to use Terraform
Good fit: managing cloud infrastructure, multi-cloud setups, teams that want reproducible environments, anything beyond a single server.
Overkill for: a single VPS, hobby projects on Vercel/Netlify (they handle infra for you), or if you only use one cloud and prefer its native tools.
For the full command reference, see the Terraform cheat sheet.
For a detailed comparison of IaC tools, see Terraform vs Pulumi. If youβre choosing a cloud provider, check AWS vs GCP vs Azure.
FAQ
Is Terraform free to use?
Terraform CLI is free and open source. HashiCorp also offers Terraform Cloud (free tier for small teams) and Terraform Enterprise (paid) which add collaboration features, remote state management, and policy enforcement.
What happens if I lose my Terraform state file?
Losing the state file means Terraform no longer knows what resources it manages. Youβd need to import existing resources back into state manually, which is tedious. Always store state remotely (S3, Terraform Cloud) with versioning and backups enabled.
Can I use Terraform for a single cloud provider, or is it only for multi-cloud?
Terraform works great with a single cloud provider. While multi-cloud is a common use case, most teams use Terraform with just AWS or just GCP. The benefit is infrastructure as code regardless of how many clouds you use.
Related: What is Serverless? A Simple Explanation for Developers