How do you migrate state from one backend to another safely?
AdvancedConceptState Internals
Answer
- Back up:
terraform state pull > backup.tfstate. - Edit the
backendblock to the new one. - Run
terraform init -migrate-stateand confirm the copy. - Run
terraform planand expect no changes. - Keep the old state read-only for a while before deleting it. Make sure nobody applies during the migration.
More on State Internals
What does the state file contain?BeginnerWhat is the difference between local and remote state?BeginnerHow do you configure the S3 backend?BeginnerWhat is state locking and why does it matter?IntermediateHow does S3-native locking work and how does it replace DynamoDB?AdvancedHow do you inspect resources in state?Beginner