terraform move code block - better way to let terraform know you have moved your resources
Sometimes we refactor our terraform code and move the basic terraform code
Let's say we have the following code
And then we refactor our code to the following code structure
The Module Code (modules/storage/main.tf)
Notice that inside the module, I've given the resource a new local name: modular_storage.
The Module Variables (modules/storage/variables.tf)
After we have refactor our code and run terraform apply, pretty sure terraform asking us to create new resources
Should IAC behave like this? Why are we adding code block to say "Hey, terraform I have move - why can't terraform maintain it's own statefile - I indirectly". What if someone deleted the code - i have to go searching for it in git histories.
So we just have to add additiona block "moved" - so fix statefile and let terraform awere.
And finally we have the plan that says no changes
Comments