vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
149 stars 33 forks source link

bug: installation_method = "network" fails with API error #330

Closed kevemueller closed 1 month ago

kevemueller commented 1 month ago

In a heterogenous environment PXE based installation is a common denominator. Other TF providers support creation of VMs that boot via PXE, perform installation and then reboot from disk.

Setting installation_method = "network" seems to be intended to support exactly this, but does not work as expected. Also it requires cdrom to be empty, which is in rare cases an unnecessary limitation. You might want to install from network with a kickstart file plugged into local cdrom.

Example TF:

data "xenorchestra_template" "vm_template" {
  name_label = "Debian Bookworm 12"
  pool_id = data.xenorchestra_pool.pool.id
}

resource "xenorchestra_vm" "vm" {
  name_label = "XO terraform tutorial"
  template = data.xenorchestra_template.vm_template.id

  installation_method = "network"

  network {
    network_id = data.xenorchestra_network.network.id
  }

  disk {
    sr_id = data.xenorchestra_sr.sr.id
    name_label = "VM root volume"
    size = 50212254720
  }
}

fails with the error

vm.create
{
  "CPUs": 1,
  "VDIs": [
    {
      "$SR": "2511d452-60b4-fe7f-8396-5ebe242043bf",
      "SR": "2511d452-60b4-fe7f-8396-5ebe242043bf",
      "name_description": "",
      "name_label": "VM root volume",
      "size": 50212254720,
      "type": "user"
    }
  ],
  "VIFs": [
    {
      "network": "803b67a1-7fda-b02b-aa16-377749a7e948"
    }
  ],
  "auto_poweron": false,
  "bootAfterCreate": false,
  "coreOs": false,
  "cpuCap": null,
  "cpuWeight": null,
  "existingDisks": {},
  "expNestedHvm": false,
  "high_availability": "",
  "hvmBootFirmware": "bios",
  "installation": {
    "method": "network",
    "repository": ""
  },
  "memoryMax": 2147467264,
  "name_description": "",
  "name_label": "XO terraform tutorial",
  "tags": [],
  "template": "41c380fe-7d26-6afb-191c-e3135fcf739e-07d91aaa-43f7-430a-bf84-0edb6714df0f",
  "vga": "std",
  "videoram": 8
}
{
  "code": 10,
  "data": {
    "errors": [
      {
        "instancePath": "/installation/repository",
        "schemaPath": "#/properties/installation/properties/repository/minLength",
        "keyword": "minLength",
        "params": {
          "limit": 1
        },
        "message": "must NOT have fewer than 1 characters"
      }
    ]
  },
  "message": "invalid parameters",
  "name": "XoError",
  "stack": "XoError: invalid parameters
    at Module.invalidParameters (/usr/local/lib/node_modules/xo-server/node_modules/xo-common/src/api-errors.js:21:32)
    at Xo.call (file:///usr/local/lib/node_modules/xo-server/src/xo-mixins/api.mjs:90:22)
    at Api.#callApiMethod (file:///usr/local/lib/node_modules/xo-server/src/xo-mixins/api.mjs:362:19)"
}

The problem is installation/repository being empty, whereas in the code it seems to be intended to have the value PXE. There is no way to manually override this, hence network booting is not working.

ddelnano commented 1 month ago

@kevemueller this seems like a duplicate of #311, which was fixed in v0.28.1. Can you confirm what version of the provider you are using and upgrade to v0.28.1 or later to retest?

As for the limitation around providing either cdrom or installation_method = "network", iirc I opted for a simpler implementation since the initial feature request didn't ask for that. I think that's reasonable to change and appreciate you surfacing this use case.

kevemueller commented 1 month ago

I have copied the provider.tf from your tutorial https://xen-orchestra.com/blog/virtops1-xen-orchestra-terraform-provider/

terraform {
  required_providers {
    xenorchestra = {
      source = "terra-farm/xenorchestra"
      version = "~> 0.9"
    }
  }
}

This installs me:

Terraform v1.8.3
on darwin_amd64
+ provider registry.terraform.io/terra-farm/xenorchestra v0.26.1

I understand that you have moved your registry to vatesfr/xenorchestra. I suggest you mention this in the above blog entry, as that is where people new to the platform tend to get their authoritative information from.

I can confirm that the version 0.29 does not show this error.

olivierlambert commented 1 month ago

Blog post edited to fix the links :+1:

kevemueller commented 1 month ago

Hi @olivierlambert, thanks for picking this up. I really appreciate your attitude to fix these small things as well, I agree that they are making a big difference when you are attracting a lot of newcomers. While you are at it, please also check https://xen-orchestra.com/docs/advanced.html#terraform-provider Link goes to the old repo.

olivierlambert commented 1 month ago

Thanks for your feedback, helping us to find all bad links :+1:

PR created: https://github.com/vatesfr/xen-orchestra/pull/7673