Company
Date Published
Author
Mariusz Michalowski
Word count
1585
Language
English
Hacker News points
None

Summary

The `terraform state mv` command ensures smooth transitions when renaming resources, reorganizing configurations, or splitting state files. It moves items within the Terraform state file without recreating or destroying them, allowing for refactoring and reorganization of Terraform resources. The command takes a source resource or module address and a destination address as input, and updates the state to reflect the new configuration structure. Improper use of `terraform state mv` can lead to mismatches between the state and infrastructure, so it's essential to validate changes after running the command. The command is useful for renaming resources, reorganizing resources into modules, fixing state issues, and moving resources across state files or modules. It differs from `terraform import`, which brings external resources under Terraform's management. The command can be used with various options, including `-state` to specify a custom state file path, `-state-out` to write the updated state file, and `-lock` to enable or disable state file locking during the operation.