Terraform Tutorial — Local vs Remote Backends
The backend determines where state is stored. Choosing the right backend is one of the most important decisions in a Terraform project.
Local Backend (Default)
By default, Terraform stores state in a local file:
project/
├── main.tf
├── terraform.tfstate ← state on your laptop
└── terraform.tfstate.backup
| Pro | Con |
|---|---|
| Simple, no setup | Only one person can use it |
| Fast (no network) | No encryption at rest |
| Good for learning | No locking |
| State lost if laptop dies |
Remote Backend
State is stored in a shared, encrypted location:
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
}
}
| Pro | Con |
|---|---|
| Team access | Requires setup (bucket, permissions) |
| Encryption at rest | Network dependency |
| Locking (DynamoDB) | Slightly slower (network calls) |
| Versioning (S3) | |
| CI/CD friendly |
When to Switch to Remote
| Scenario | Use Remote? |
|---|---|
| Learning on your own | ❌ Local is fine |
| Working with a team | ✅ Yes |
| Running in CI/CD | ✅ Yes |
| Managing production infra | ✅ Yes |
| Storing sensitive data in state | ✅ Yes (encryption) |
Available Backend Types
| Backend | Provider | Best For |
|---|---|---|
s3 |
AWS | AWS-centric teams |
azurerm |
Azure | Azure-centric teams |
gcs |
GCP | GCP-centric teams |
remote |
Terraform Cloud | Teams using HCP Terraform |
consul |
HashiCorp | HashiCorp stack users |
pg |
PostgreSQL | Database-backed state |
What’s Next?
Let’s set up the most popular remote backend: S3 with DynamoDB locking.