Terraform State Backends: Choosing and Configuring Remote State
Configure remote state backends for team collaboration, state locking, and disaster recovery
February 26, 2026 · 7 min · 1383 words · Rob Washington
Table of Contents
Local Terraform state works for learning. Production requires remote state—for team collaboration, state locking, and not losing your infrastructure when your laptop dies. Here’s how to set it up properly.
# backend.tf
terraform {
backend"s3" {
bucket="mycompany-terraform-state" key="prod/infrastructure/terraform.tfstate" region="us-east-1" encrypt=true dynamodb_table="terraform-state-locks" # role_arn configured via CLI or environment
}
}
1
2
3
4
5
6
7
# Initialize with roleterraform init \
-backend-config="role_arn=arn:aws:iam::123456789:role/TerraformRole"# Or use environmentexportAWS_ROLE_ARN="arn:aws:iam::123456789:role/TerraformRole"terraform init
# S3/DynamoDB - check the tableaws dynamodb scan --table-name terraform-state-locks
# Force unlock (dangerous - only if lock is stale)terraform force-unlock LOCK_ID
# List resourcesterraform state list
# Show specific resourceterraform state show aws_instance.web
# Pull remote state locallyterraform state pull > state.json
# Rename resourceterraform state mv aws_instance.web aws_instance.webserver
# Move to moduleterraform state mv aws_instance.web module.compute.aws_instance.web
# Move between state filesterraform state mv -state-out=other.tfstate aws_instance.web aws_instance.web
# Initialize/reconfigure backendterraform init -reconfigure
# Migrate between backendsterraform init -migrate-state
# List stateterraform state list
# Show resourceterraform state show RESOURCE
# Move resourceterraform state mv SOURCE DEST
# Remove from stateterraform state rm RESOURCE
# Import existingterraform import RESOURCE ID
# Force unlockterraform force-unlock LOCK_ID
Remote state is non-negotiable for any serious Terraform usage. Start with S3 + DynamoDB for AWS, enable versioning from day one, and never share state files outside your backend. The 30 minutes spent setting this up saves hours of state recovery later.
📬 Get the Newsletter
Weekly insights on DevOps, automation, and CLI mastery. No spam, unsubscribe anytime.