When do you use `terraform state mv`?
IntermediateConceptState Internals
Answer
To rename a resource or move it between modules or state files without destroying it, for example after refactoring.
terraform state mv aws_instance.web module.app.aws_instance.web
terraform state mv -state-out=other.tfstate aws_s3_bucket.b aws_s3_bucket.b
It edits state only, so run plan afterwards to confirm no diff. Prefer moved blocks when you can, since they are reviewable and travel with code.
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