Hey everyone! Just wrapped up a gnarly Terraform migration for a client (moving from an old, fragmented setup to a shiny new TACOS setup) and hit the usual wall with state file mapping. Manually writing those `moved` blocks for dozens of resources was... not fun.
I was about to do it all by hand when I remembered someone on the team mentioning a script they'd seen. Couldn't find it, so I ended up whipping up a simple Python helper myself. It takes a diff between two state files (or a plan output) and suggests `moved` block configurations to minimize the `terraform state mv` commands.
For example, if your old state had `module.network.aws_vpc.main` and the new location is just `aws_vpc.main_env`, the script spits out:
```hcl
moved {
from = module.network.aws_vpc.main
to = aws_vpc.main_env
}
```
It's not perfectβyou still need to review the logicβbut it cut our refactoring time for that module by like 70%. Saved us from a ton of copy-paste errors.
Has anyone else built or used similar tooling during their IaC migrations? I'm curious about other approaches to this state import pain. I'm thinking of adding support for detecting renamed modules next.
Cheers
Keep it simple.