vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
151 stars 32 forks source link

With the version 0.24.1 it is not possible to remove the affinity host on an existing VM. #238

Closed bufanda closed 1 year ago

bufanda commented 1 year ago

I have a VM I had configured an affinity host, now with an expanded cluster and reworking some of the VM distribution I want this one particular VM to not have a affinity to one particular host anymore. So I removed the affinity host rule from the terraform file but now I get the following error.

╷
│ Error: jsonrpc2: code 10 message: invalid parameters: {"errors":[{"instancePath":"/affinityHost","schemaPath":"#/properties/affinityHost/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"}]}
│
│   with xenorchestra_vm.aegir,
│   on instance-aegir.tf line 1, in resource "xenorchestra_vm" "aegir":
│    1: resource "xenorchestra_vm" "aegir" {
│
╵

As the affinity host rule os only optional per documentation shouldn't it be possible to remove the rule and have terraform remove the setting from the host? Or do I have to destroy the VM and recreate it. Which sure would be possible but it isn't the behaviour I would expect. As in the gui I can simply click on the 'X' to remove the affinity.

ddelnano commented 1 year ago

Hi @bufanda, thanks for reporting this issue.

It is definitely possible for terraform to handle this case properly. At the moment, I don't know if this is additional fallout from the XO api preventing empty string params (#231) or if the changes to address that caused a new bug. In any case, the provider should be able to handle this.

I'm currently traveling through April 23rd, but I'm hoping to have time to address this. In the meantime, I would use terraform's ignore_changes meta argument and remove the affinity host from the UI (note the code below is an example and was not tested):

resource "xenorchestra_vm" "vm_name" {

[ .. ]
  lifecycle {
    ignore_changes = [affinity_host],
  }
}

That should allow you to continue using the provider to manage these resources until the bug is fixed.

bufanda commented 1 year ago

Hi,

the ignore_changes works for now. Thanks.

exu-g commented 1 year ago

I found a workaround to remove affinity. Simply set the affinity_host the pool id. This makes the affinity None in Xen Orchestra.

  affinity_host = data.xenorchestra_pool.pool.id
bufanda commented 1 year ago

I found a workaround to remove affinity. Simply set the affinity_host the pool id. This makes the affinity None in Xen Orchestra.

  affinity_host = data.xenorchestra_pool.pool.id

Tried it. When you have a VM stopped it won't start anymore as the affinity host wiht the pool id doesn't exists.

You'll get an error message like this

You gave an invalid object reference. The object may have recently been deleted. The class parameter gives the type of reference given, and the handle parameter echoes the bad value given.
class: host
handle: b0b45af2-b561-5cc7-fc28-0a65b3aa32e0
exu-g commented 1 year ago

@bufanda yeah, you're right. I should've tested that more than just checking if the host was removed.

ddelnano commented 1 year ago

This will be fixed in v0.24.2, which will be available when this GitHub action completes.

Sorry that this has taken quite a while to be addressed!