Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Initialization always recrete the VM #30

Open
itek09 opened this issue Jun 1, 2020 · 4 comments
Open

[BUG] Initialization always recrete the VM #30

itek09 opened this issue Jun 1, 2020 · 4 comments

Comments

@itek09
Copy link

itek09 commented Jun 1, 2020

Describe the bug
If you create a vm resource with initialization block, every terraform apply will recreate the virtual machine

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple vm with initialization and execute terraform apply
  2. Without destroy the resources, reexecute terraform apply
  3. You will see that the vm resource should be recreated

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

@itek09
Copy link
Author

itek09 commented Jun 7, 2020

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 ;)

@danitso-dp
Copy link
Collaborator

@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 :)

@diijkstra
Copy link

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.

@danitso-dp
Copy link
Collaborator

@itek09 do you still experience this issue using the latest version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants