3 ms·
I know many people find it painful but isn't this fairly simple with "terraform state mv?" my process is roughly: comment out the resource in the module, run
by JohnMakin 2y ago
I know many people find it painful but isn't this fairly simple with "terraform state mv?"
my process is roughly:
comment out the resource in the module, run a plan -> get output like:
"module.foo1.aws_resource.bar will be deleted"
Then copy my resource in source to module.foo2.aws_resource.bar, the command becomes:
terraform state mv module.foo1.aws_resource.bar module.foo2.aws_resource.bar
I guess this might be harder if you're using upstream "official" modules, but I avoid those like the plague.
- rjbwork 2y agoYou don't even need to do state mv anymore. They added the `moved` block a while ago. You can then delete it from the source after your apply at your leisure.
- hamandcheese 2y ago"Every change requires two PRs that aren't in the same terraform run" still way way way too much mental overhead just to do a simple refactor.
- hamandcheese 2y agoYea, there are tools to work around it, but the fact that a pure refactor would impact terraform state at all is the design flaw in my eyes. Suddenly, just to refactor the source in a way that shouldn't touch any resources, you have to have be able to mutate the terraform state. (Or use the more recently introduced moved blocks, which is still quite a big kludge). This means any kind of broadly sweeping refactor (which might impact many different state files) is really hard.