The original tfmv
tool: kozzztya/tf-state-mover.
The original fix for Terraform version >= 0.12.0
: seboudry/tf-state-mover
My fork extends the tool functionality to provide additional options and upgrade interaction with CLI interface. Check the CHANGELOG.md for details about current features and TODO.md for the future enhancements.
Interactive CLI for moving resources in a Terraform state.
Sometimes you need to refactor your config. Move resources to the separate module, rename a resource, etc.
Terraform will plan to recreate resources in this case. You can use command terraform state mv
to prevent this.
But it can be pretty routine. This tool helps you easily do this. Just select from the list source resource, then destination, press enter, repeat.
I don't have the access to the original [npm project repository](https://www.npmjs.com/package/tfmv?activeTab=readme, so we need to build the tool from source code.
- Clone the repo
git clone https://github.com/VolodymyrSmahliuk/tf-state-mover.git
- Build the application package from source code by
npm
npm pack
- Install the application from the package created on the previous step
npm install --global tfmv-<app-version>.tgz
- Clone the repo
git clone https://github.com/VolodymyrSmahliuk/tf-state-mover.git
- Install required packages
npm install
- Run the
index.js
from the root module of your Terraform code
node <path-to-this-repo>/index.js
Run state move for the whole Terraform code
tfmv
Or use -target
option
tfmv -target=module.meaningful_name -target=module.meaningful_name_new