vatesfr / terraform-provider-xenorchestra

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

Enable NetworkConfig cloud-init input on vm-create #237

Closed deefdragon closed 1 year ago

deefdragon commented 1 year ago

If you wish to use network-config to set network settings, you must provide a seperate network config file as the network data can not be loaded from the user data. Xen orchestra passes this data from the frontend via a value called networkConfig (akin to the cloudConfig value). It looks like this value exists, but is set to be ignored here. Is there some other reason this was disabled or can it be enabled and no longer ignored?

4censord commented 1 year ago

I don't get the question. The cloud Network Config part of the vm resource seems to work as intended on my end, or was at least ~3 weeks ago.

deefdragon commented 1 year ago

Cloudinit is apperently notoriously inconsistent between oses and versions.

I'm running Ubuntu 22.04, and have gotten an explicit error in my cloud init logs that I can't load the network config in via the user data.

timmy59100 commented 1 year ago

I don't get the question. The cloud Network Config part of the vm resource seems to work as intended on my end, or was at least ~3 weeks ago. @4censord

How did you do the cloud Network Config part? tf/cloudconfig files would be interesting to see. Would be great if you could share an example.

4censord commented 1 year ago

Of course.

This is my network-config.tmpl

network:
  version: 1
  config:
    - type: physical
      name: enX0
      subnets:
        - type: static
          address: ${ip_address}/24
          gateway: ${gateway}

Relevant parts of my terraform files:

resource "xenorchestra_cloud_config" "network_data" {
  name     = "${local.projekt}/nextcloud network-data"
  template = templatefile("${path.module}/templates/network.yaml.tmpl", {
    ip_address = "192.168.100.100"
    gateway = 192.168.100.254
  })
}

resource "xenorchestra_vm" "vm" {
  name_label = "name"
  template   = data.xenorchestra_template.template.id

  cpus       = 4
  memory_max = 8 * local.gib

  cloud_config         = xenorchestra_cloud_config.user_data.template
  cloud_network_config = xenorchestra_cloud_config.network_data.template

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

  disk {
    sr_id      = data.xenorchestra_sr.storage.id
    name_label = "disk"
    size       = 10 * local.gib
  }
}

This is used with a custom cloudinit enabled template based on archlinux.

ddelnano commented 1 year ago

It looks like this value exists, but is set to be ignored here. Is there some other reason this was disabled or can it be enabled and no longer ignored?

@deefdragon the value you linked to is used (source).

When using cloud-init there are many moving parts (OS/distro type, cloud-init version and other supporting software/packages It's extremely difficult to debug this without the terraform code, cloud-init, terraform and other relevant logs. Please more details on this and I'd specifically like to see the error mentioned below:

I'm running Ubuntu 22.04, and have gotten an explicit error in my cloud init logs that I can't load the network config in via the user data.

timmy59100 commented 1 year ago

@4censord Great, thanks. That worked with the ubuntu 20.04 template.

ddelnano commented 1 year ago

Closing this since you were able to get it working. If you need more assistance debugging this, feel free to continue the discussion here or in Discord.