State is Terraform's source of truth about what resources exist.
Problems with local state:
- Team members overwrite each other's changes
- State file contains secrets
- No locking during concurrent applies
Remote state solution:
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-west-2"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
Interview question: "How do you prevent concurrent Terraform applies from corrupting state?"
Use remote state with locking (DynamoDB for S3, GCS has built-in locking).