0
votes

I'm performing refactoring in a few Terraform files. One of the tasks is renaming resources from kebab-case to snake_case.

To prevent the destruction and recreation of said resources, I used terraform state mv. Now, for some reason I'm hoping to understand here, it still destroys resources. I see 2 issues:

1- The IDs get computed again.

2- The references to variables are taken as literals.

Example:

-/+ aws_volume_attachment.att_ebs_caldat_axon_apps (new resource required)
      id:                                                 "vai-4287143552" => <computed> (forces new resource)
      device_name:                                        "/dev/xvdb" => "/dev/xvdb"
      force_detach:                                       "true" => "true"
      instance_id:                                        "i-0ca294d44635d3ace" => "${module.instance_axon.instance_id}" (forces new resource)
      volume_id:                                          "vol-0298f5247bb2aa312" => "${aws_ebs_volume.ebs_caldat_axon_apps.id}" (forces new resource)

I'm using Terraform 0.11.14

The command for moving the state for this resource was terraform state mv aws_volume_attachment.att-ebs-caldat-axon-apps aws_volume_attachment.att_ebs_caldat_axon_apps

I don't know what I'm missing. Any help is appreciated.

1
Can you follow this doc , its well written ryaneschinger.com/blog/terraform-state-move , you need to also think of dependencies and work bottom to top approach .Also to comment anything we need to know your whole config fileSurya Prakash Patel
So according to that article I should've done the state moves in a specific order taking resource dependencies into account... I honestly thought if I did them all at once it would work... Now I guess I need to figure out how to rollback the state since I'm in remote and moreover it is a production env.Sanne Tuin
I suggest you to backup your state file ( as it is prod ) and try editing statesSurya Prakash Patel
There is one state file backup per (apparently) each state mv that I performed. Would it be safe to do a state push of the oldest backup to revert all the performed moves? It requires a -force flag since "the destination state has a higher serial number"Sanne Tuin
Can you post your resource block code?m0hit

1 Answers

0
votes

Turns out terraform will recreate the EBS resources if you change either their volume or attachment names even if you perform a state mv. I don't fully understand the reason for this but the same behavior is not encountered when doing the same with other resources i.e. security groups.

Thank you.