Which command is used to move a resource from one state file to another, commonly used when refactoring modules?
terraform state mv relocates a resource entry between state files or addresses, updating the state to match refactored configuration without destroying or recreating infrastructure. This satisfies the module-refactoring scenario by preserving existing resources while their configuration addresses change.
Why this answer
terraform state mv moves a resource from one state address to another, and when used with different state files (via -state and -state-out), it can move resources between state files. This is the standard command for refactoring modules without destroying and recreating resources. It updates the state mapping so Terraform associates the existing resource with the new address.
Exam trap
The trap is inventing commands like terraform migrate or plan -refactor — only terraform state mv (and terraform state push/pull for whole files) can move resources between states.
How to eliminate wrong answers
Option A is wrong because terraform migrate is not a real Terraform command. Option B is wrong because terraform plan -refactor does not exist; plan has no refactor flag. Option C is wrong because terraform refresh only reconciles state with real infrastructure, it does not move resources between state files or addresses.