terraform-provider-xenorchestra: Cannot use cloud_config while creating VM

I’m currently facing an issue, where we can create a cloud config in XO (or have it created with resource "xenorchestra_cloud_config") but when used to initialize a new VM, it doesn’t get applied.

I’ve verified that:

  • the desired template is working (when I create a VM manually in XO and use the template + the given cloud config, it works)
  • the cloud config itself must be working as well (due to previous point)
  • Terraform can create a working cloud config

What I’ve tried:

  • manually creating the cloud config and fetching it with data "xenorchestra_cloud_config" "cc" and using that
  • creating the cloud config with Terraform (resource "xenorchestra_cloud_config" "cc") and using that
  • using hashicorp/cloudinit provider (data "cloudinit_config" "cloudinit_config"), passing the config into part.content and using that
  • inlining the cloud config directly into xenorchestra_vm.cloud_config with newlines or <<EOF ... EOF

Nothing seems to work. I’ve tried running terraform apply with TF_LOG_PROVIDER=DEBUG and I’ve noticed that the inputted cloud config made it all the way to the RPC call:

(I tried to format this with line breaks)

2023-02-26T01:31:42.221+0100 [INFO]  provider.terraform-provider-xenorchestra_v0.24.0: 2023/02/26 01:31:42 [TRACE] Made rpc call `vm.create` with params: map[CPUs:1 VDIs:[] VIFs:[map[mac: network:93f364f7-387a-8565-08c6-5f775d9fc95c]] 
affinityHost: bootAfterCreate:true 
cloudConfig:#cloud-config
hostname: {name}%
packages:
- htop
growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false 
coreOs:false 
cpuCap:<nil> 
cpuWeight:<nil> 
existingDisks:map[0:map[$SR:6a1ecde0-b5a2-bc27-91bc-49b463570450 SR:6a1ecde0-b5a2-bc27-91bc-49b463570450 name_description:OS name_label:hdd size:50212254720 type:user]] 
expNestedHvm:false 
hvmBootFirmware:bios 
memoryMax:1073733632 
name_description:popisek, lalala laalla 
name_label:krolda - novější2 
tags:[terraform-test] 
template:8db93d20-ee94-9b52-d899-6d27128b41e4 vga:std videoram:8] 
and received 80f72175-162a-887d-4162-5ce9d325140c: result with error: <nil>: timestamp=2023-02-26T01:31:42.221+0100

However a bit later when we’re waiting for the VM to be created, I’m receiving logs like this (notice CloudConfig: ResourceSet:<nil>):

2023-02-26T01:31:42.376+0100 [INFO]  provider.terraform-provider-xenorchestra_v0.24.0: 2023/02/26 01:31:42 [DEBUG] Found the following objects for type 'client.Vm' from xo.getAllObjects:
 [{Addresses:map[0/ipv4/0:192.168.1.168 0/ipv6/0:fe80::9451:90ff:fe02:6b07] 
BlockedOperations:map[] 
Boot:{Firmware:bios} Type:VM Id:80f72175-162a-887d-4162-5ce9d325140c 
AffinityHost: 
NameDescription:popisek, lalala laalla
 NameLabel:krolda - novější2 
CPUs:{Number:1 Max:2} 
ExpNestedHvm:false 
Memory:{Dynamic:[1073733632 1073733632] Static:[536870912 2147483648] Size:1073733632} 
PowerState:Halted 
VIFs:[a183688b-d4d8-3a50-05d3-4d0a775eca5d] 
VBDs:[34f04a3c-c06d-2058-60ea-65189e6d7ff9 34af4ff6-b17b-0be3-93a2-466f8e84d162] 
VirtualizationMode:hvm 
PoolId:601f08a4-0b01-6f12-1b89-1b6346f09ddf 
Template: 
AutoPoweron:true 
HA: 
CloudConfig: ResourceSet:<nil> 
Tags:[terraform-test] 
Videoram:{Value:8} 
Vga:std 
StartDelay:0 
Host:601f08a4-0b01-6f12-1b89-1b6346f09ddf 
Disks:[] 
CloudNetworkConfig: 
VIFsMap:[] 
WaitForIps:false 
Installation:{Method: Repository:} 
ManagementAgentDetected:false 
PVDriversDetected:false}]: timestamp=2023-02-26T01:31:42.376+0100

The result is:

  • the machine is created properly
  • the XO CloudConfigDrive is created
  • the cloud config never runs during the boot and what is written in it doesn’t get executed
  • log files /var/log/cloud-init[-output].log obviously don’t exist either

System info:

  • Terraform version v1.3.8
  • terra-farm/xenorchestra version 0.24.0
  • XenOrchestra is self hosted
    • xo-server 5.109.3
    • xo-web 5.111.1
    • commit ee837

Attempted Cloud config:

#cloud-config
hostname: {name}%
packages:
  - htop
growpart:
  mode: auto
  devices: ['/']
  ignore_growroot_disabled: false

Terraform file:

# Instruct terraform to download the provider on `terraform init`
terraform {
  required_providers {
    xenorchestra = {
      source = "terra-farm/xenorchestra"
    }
    cloudinit = {
      source = "hashicorp/cloudinit"
    }
  }
}

# https://registry.terraform.io/providers/terra-farm/xenorchestra/latest/docs

# Configure the XenServer Provider
provider "xenorchestra" {
  #   # Must be ws or wss
  #   url      = "ws://hostname-of-server" # Or set XOA_URL environment variable
  #   username = "<username>"              # Or set XOA_USER environment variable
  #   password = "<password>"              # Or set XOA_PASSWORD environment variable

  #   # This is false by default and
  #   # will disable ssl verification if true.
  #   # This is useful if your deployment uses
  #   # a self signed certificate but should be
  #   # used sparingly!
  insecure = true # Or set XOA_INSECURE environment variable to any value
}

data "xenorchestra_pool" "pool" {
  name_label = "..."
}

data "xenorchestra_template" "template" {
  name_label = "..."
  pool_id    = data.xenorchestra_pool.pool.id
}

data "xenorchestra_network" "net" {
  name_label = "Pool-wide network associated with eth0"
  pool_id    = data.xenorchestra_pool.pool.id

}

data "xenorchestra_sr" "local_storage" {
  name_label = "Local storage"
  pool_id    = data.xenorchestra_pool.pool.id
  tags       = ["s4"]
}

data "xenorchestra_cloud_config" "cloud_config" {
  name = "test123"
}

data "cloudinit_config" "cloudinit_config" {
  gzip = false
  base64_encode = false
  part {
    content_type = "text/cloud-config"
    content = templatefile("cloud_config.tftpl", {
      hostname = "your-hostname"
      domain = "your.domain.com"
    })
  }
}

resource "xenorchestra_cloud_config" "bar" {
  name = "cloud config name"
  # Template the cloudinit if needed
  template = templatefile("cloud_config.tftpl", {
    hostname = "your-hostname"
    domain = "your.domain.com"
  })
}

resource "xenorchestra_vm" "bar" {
  memory_max = 1073733632
  cpus       = 1
  cloud_config = xenorchestra_cloud_config.bar.template
  name_label       = "name"
  name_description = "label"
  template         = data.xenorchestra_template.template.id
  auto_poweron  = true

  # Prefer to run the VM on the primary pool instance
  # affinity_host = data.xenorchestra_pool.pool.master
  network {
    network_id = data.xenorchestra_network.net.id
  }

  disk {
    sr_id            = data.xenorchestra_sr.local_storage.id
    name_label       = "hdd"
    name_description = "OS"
    size             = 50212254720
  }

  tags = [
    "terraform-test",
  ]

  // Override the default create timeout from 5 mins to 20.
  timeouts {
    create = "20m"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@TheiLLeniumStudios thanks for the extremely detailed report and glad to hear that the XO team is working on the fix!