Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



You 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.


"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.


Yea, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: