I am trying to move some existing resource to another module within Terraform code. I currently have some Azure machines that have been deployed via an old local module named ‘newvm’:
Am I doing something wrong here? I am assuming this is due to the password being a sensitive string, however I would have expected Terraform to still just be able to change the reference in it’s state data without wanting to recreate the VM?
Are there any other changes indicated in the plan?
Where is the random_string resource? How does it connect to the configuration of the VM?
It would probably be more clear what’s going on if you made the changes one at a time. First move the module and update any references, which should produce no changes since you are only refactoring existing configuration. Then go ahead and upgrade the module. This way you can tell the difference between mistakes you may have made in refactoring, vs mistakes in configuring the new module version.
There are other changes indicated in the plan, but they all stem from the password change, for example we save passwords as a key vault secret therefore that secret wants to be deleted and re-created. Our secrets expire after x amount of time so a new time_offset_secret_expiration object wants to be created. I use the domain_join extension so this wants to be removed / reinstalled since the VM wants to be rebuilt and so on.
In terms of changes in the module, they are all insignificant really; it’s more of a centralisation / management change that I am trying to do. The module is published and used elsewhere so making module changes will have further impacts.
The random_string resource is defined as shown above in my main.tf. It is then used as shown below:
In terms of the amount of changes, the admin password is the only one I am trying to get working right now. Once tf can accept the existing value I can move on to getting the other changes working!.
Unfortunately without the plan output and/or a more complete example I really can’t tell what is going on. I would start by eliminating variables between the changes you are making, and that you can get an empty plan between each step. Make sure Terraform is up to date and you have not changed any provider versions; then move the module name in the configuration and apply the result; then update the module.