What is Terraform state and why must it be stored remotely in a team environment?
Terraform state is a JSON file (terraform.tfstate) that maps your configuration to real-world resources. Terraform uses it to know what already exists before planning changes.
Storing it locally breaks team collaboration:
- Team members would each have different state files causing conflicts
- State file gets lost if the local machine breaks
- No locking mechanism — two engineers could run
applysimultaneously and corrupt state
Remote backends (S3 + DynamoDB for locking, GCS, Terraform Cloud) solve all three problems.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-lock"
}
}