Skip to main content

Terraform Backend

A Terraform backend defines where Terraform stores its state and how operations run. The default is a local file, while teams use remote backends like S3, GCS, Azure Blob, or Terraform Cloud.

What Is a Backend?

A remote backend gives every engineer and pipeline one shared state, with locking and history.

Backend State storage Locking
local Local disk Single machine
s3 AWS S3 Lock file or DynamoDB
gcs, azurerm Cloud storage Built in
Bash
terraform init # configure a new backend
terraform init -reconfigure # use new settings, no migration
terraform init -migrate-state # copy state to the new backend

Backend blocks cannot use variables. For per-environment values, leave the block empty and pass -backend-config flags at init.

Common Mistake

Managing the state bucket in the same configuration that stores state there. Bootstrap it separately.

Frequently Asked Questions

What is the difference between a backend and a provider?

A provider talks to a platform like AWS to manage resources. A backend decides where state is stored.

What should I do before migrating from local to remote state?

Back up terraform.tfstate, have one person migrate, run terraform init -migrate-state, then confirm terraform plan shows no unexpected changes.

Found a mistake, an outdated step or a broken link?