Interview Prep/Terraform/State Internals

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.

All Terraform questions Roadmap: Terraform in production

More on State Internals