Terraform state management and workspace strategies

4893
0

Terraform state tracks the mapping between configuration and real infrastructure. Remote state backends like S3, GCS, or Terraform Cloud enable team collaboration. DynamoDB provides state locking to prevent concurrent modifications. The terraform_remote_state data source reads outputs from other state files. State splitting separates concerns—networking, compute, and databases in separate states. Workspaces (terraform workspace) create isolated state per environment from the same configuration. The terraform state mv command refactors resources between states. terraform import brings existing infrastructure under management. State encryption protects sensitive values. terraform state rm removes resources from state without destroying them. Regular state backups prevent data loss.