I have started working on terraform very recently, One of the biggest annoying factors was when you have to change the terraform state without a forced replacement of the resource.
Terraform remembers a state which is nothing but how the infrastructure looks in the remote real world and in the local configuration.
So when you change a few attributes in the resource like name of the resource, instances, modules which are already created, in the plan it specifies that as not an in-place change
Thankfully there is a command that my colleague has mentioned is "mv"
This command is nothing but like a Linux mv command.
You need to specify source and destination:
terraform state mv aws_subnet.main aws_subnet-us-west-2c
This will move the existing terraform state to an updated terraform state and when you run a terraform plan, you should not see any infrastructure changes if done correctly.
For more information, you can refer: https://www.terraform.io/docs/commands/state/mv.html
Top comments (0)