terraform-provider-proxmox
terraform-provider-proxmox copied to clipboard
Live Migration error: retrieving VM 100: the requested resource does not exist
Hey there,
if I manually migrate a VM to a different Proxmox host within my Cluster I do receive an error if I run OpenTofu again.
╷
│ Error: error retrieving VM 100: the requested resource does not exist
│
│ with proxmox_virtual_environment_vm.vm["testserver01"],
│ on proxmox_vm.tf line 5, in resource "proxmox_virtual_environment_vm" "vm":
│ 5: resource "proxmox_virtual_environment_vm" "vm" {
│
╵
The Live Migration to the previous host seems to be completed fine and afterwards OpenTofu is showing no errors.
Is this error expected?
Cheers - Willi
Hey @willifehler 👋🏼
Could you post your tofu output after the first and then second run?
Sure @bpg. Thank you so much for your support. I will cut the output of OpenTofu, there are also Ansible resource changes which I skip here.
tofu plan
114 # proxmox_virtual_environment_vm.vm["testserver"] will be updated in-place
115 ~ resource "proxmox_virtual_environment_vm" "vm" {
116 id = "100"
117 name = "testserver"
118 ~ node_name = "pve2" -> "pve3"
119 tags = [
120 "opentofu",
121 "test",
122 ]
123 # (26 unchanged attributes hidden)
124
125 # (7 unchanged blocks hidden)
126 }
127
128 Plan: 2 to add, 1 to change, 0 to destroy.
tofu apply
228 # proxmox_virtual_environment_vm.vm["testserver"] will be updated in-place
229 ~ resource "proxmox_virtual_environment_vm" "vm" {
230 id = "100"
231 name = "testserver"
232 ~ node_name = "pve2" -> "pve3"
233 tags = [
234 "opentofu",
235 "test",
236 ]
237 # (26 unchanged attributes hidden)
238
239 # (7 unchanged blocks hidden)
240 }
241
242 Plan: 2 to add, 1 to change, 0 to destroy.
243 proxmox_virtual_environment_vm.vm["testserver"]: Modifying... [id=100]
244 ╷
245 │ Error: error retrieving VM 100: the requested resource does not exist
246 │
247 │ with proxmox_virtual_environment_vm.vm["testserver"],
248 │ on proxmox_vm.tf line 5, in resource "proxmox_virtual_environment_vm" "vm":
249 │ 5: resource "proxmox_virtual_environment_vm" "vm" {
250 │
251 ╵
After the migration is finished tofu plan isn't showing anything which is related to the VM. (100)
Hey @willifehler, it looks like you didn't use the migrate attribute. Could you please try that and report back?
I've also done some tests for VM migration in another ticket, and it worked for me.
Marking this issue as stale due to inactivity in the past 180 days. This helps us focus on the active issues. If this issue is reproducible with the latest version of the provider, please comment. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!
For anyone else finding this bug report after searching for the error message, as far as I can tell, this can be reproduced with HA VMs, because that spawns two tasks in Proxmox's task log:
- first "HA
- Migrate" - that finishes in a second - second "VM
- Migrate" - this is only created after terraform crashed with its the requested resource does not existerror, presumably because it assumed the first task was the VM migration
In my case the HA resource wasn't terraform managed, so that wouldn't really be a bug in the terraform provider. I haven't tested yet what happens with terraform managed HA resources.
Added a note to the README about the HA use case. The provider doesn't really support migrations performed by HA outside of provider's control.
I've finally gotten around to manage the ha relationships as proxmox_virtual_environment_hagroup / proxmox_virtual_environment_haresource resources, but the behaviour is the same:
$ tofu state list
proxmox_virtual_environment_hagroup.hagroups["ha-infra-all"]
proxmox_virtual_environment_haresource.haresources["test-vm"]
proxmox_virtual_environment_vm.tpl_generic["test-vm"]
$ #change the vm's node_name, with migrate=true
$ tofu apply
[…]
OpenTofu will perform the following actions:
# proxmox_virtual_environment_vm.tpl_generic["test-vm"] will be updated in-place
~ resource "proxmox_virtual_environment_vm" "tpl_generic" {
~ node_name = "node1" -> "node2"
}
Plan: 0 to add, 1 to change, 0 to destroy.
[…]
proxmox_virtual_environment_vm.tpl_generic["test-vm"]: Modifying... [id=102]
╷
│ Error: error retrieving VM 102: the requested resource does not exist
│ received an HTTP 500 response - Reason: Configuration file 'nodes/node2/qemu-server/102.conf' does not exist
The migration works fine in the background, it's just that the haresource gets migrated first, and the first API call returns after the haresource is migrated but before the asynchronous VM migration is started by proxmox.
I feel like the case "terraform defined haresource for terraform defined VM" should be covered, if only in that the provider detects it and returns success after the haresource migration finished, without waiting for the VM migration, so we don't get spurious error messages.