Open itek09 opened 4 years ago
Finally I did a workaround:
For the User key, I saw in your documentation the usage of the function "trimspace", and this solve this issue.
For the username, I forced the username to a fixed one.
Other issues related to related to recreate: -If you do not define the vm_id parameter, the resource will recreate the machine. Finally I decided to force the id per machine. -If you are initialising a network adapter, the network device id always change. It will not recreate the machine only modify, but the modification require VM reboot. In my case (latest version of Proxmox), the /reboot endpoint is not implemented, so I changed this function in the provider code to use /shutdown and /start endpoints.
From my side, we can close the issue, but I will let you do it, maybe you want to check or improve these details ;)
@itek09 I'll let it remain open so I can check up on the issues you experienced. We can probably refine it a bit more :)
I have similar problem with initialization
block. I'm using using custom packer image to create a template VM. I don't want to specify anything in initialization
and it seems to be consistent with documentation - marked as being optional. Template is created properly. Unfortunately on subsequent run, terraform will try to replace (destroy/create) template in order to remove empty initialization
block.
The workaround in my case is to use lifecycle management and ignore changes in initialization
. Unfortunately specifying empty block, adds implicit datastore_id
to the block and plan.
Side note, it would be useful to mark the reason for replacement in such case, it took me some time to discover that initialization is a culprit and not a mac-address or any other usual small changes. There were no meaningfull changes in state files after recreating such template.
For the User key, I saw in your documentation the usage of the function "trimspace", and this solve this issue.
Thank you for that! I've had the same issue with multiline description
, trimspace saved the day.
@itek09 do you still experience this issue using the latest version?
Describe the bug If you create a vm resource with initialization block, every
terraform apply
will recreate the virtual machineTo Reproduce Steps to reproduce the behavior:
terraform apply
terraform apply
Expected behavior If something in the recreation block changes, we should create the VM.
Initialization info first apply
initialization.#: "" => "1" \ initialization.0.datastore_id: "" => "shared" \ initialization.0.user_account.#: "" => "1" \ initialization.0.user_account.0.keys.#: "" => "1" \ initialization.0.user_account.0.keys.0: "" => "my-key\n"
Initialization info second apply
initialization.#: "1" => "1" \ initialization.0.datastore_id: "shared" => "shared" \ initialization.0.user_account.#: "1" => "1" \ initialization.0.user_account.0.keys.#: "1" => "1" \ initialization.0.user_account.0.keys.0: "my-key" => "my-key\n" (forces new resource) \ initialization.0.user_account.0.username: " " => "" (forces new resource)
As you can see, you are adding a '\n' to the key and proxmox give you " " as username (instead of "" that you apply).
Thank you so much