Hi all,
I was able to create VMs using my Terraform code until I set the parameter destroy_cloud_config_vdi_after_boot to true.
Initially, it created a virtual machine and, after booting, removed the Cloud-Init disk as expected. However, from that point on, the VM started being created without a disk, even though tofu apply shows the following:
+ disk {
+ name_label = "carlo123-osdisk"
+ position = (known after apply)
+ size = 32212254720
+ sr_id = "589dad4d-2391-c2a9-589c-d34a9a7757ea"
+ vbd_id = (known after apply)
+ vdi_id = (known after apply)
}
tofu apply failes with:
│ Error: jsonrpc2: code -32000 message: Can't create cloud init config drive for VM without disks: {"message":"Can't create cloud init config drive for VM without disks","name":"Error","stack":"Error: Can't create cloud init config drive for VM without disks\n at Xapi.createCloudInitConfig (file:///opt/xo/xo-builds/xen-orchestra-202510281611/@xen-orchestra/xapi/vm.mjs:418:13)\n at Xo.<anonymous> (file:///opt/xo/xo-builds/xen-orchestra-202510281611/packages/xo-server/src/api/vm.mjs:191:26)\n at Task.runInside (/opt/xo/xo-builds/xen-orchestra-202510281611/@vates/task/index.js:175:22)\n at Task.run (/opt/xo/xo-builds/xen-orchestra-202510281611/@vates/task/index.js:159:20)\n at Api.#callApiMethod (file:///opt/xo/xo-builds/xen-orchestra-202510281611/packages/xo-server/src/xo-mixins/api.mjs:469:18)"}
│
│ with module.vm.xenorchestra_vm.vm,
│ on ../modules/vm/main.tf line 20, in resource "xenorchestra_vm" "vm":
│ 20: resource "xenorchestra_vm" "vm" {```
This my main.tf
data "template_file" "cloud_config" {
template = file("${path.module}/cloud-init.yaml.tftpl")
vars = {
hostname = var.vm_name
}
}
data "template_file" "cloud_network_config" {
template = file("${path.module}/network-config.yaml.tftpl")
vars = {
ip_address = var.ip_address
netmask = var.netmask
gateway = var.gateway
dns = join(", ", var.dns)
}
}
resource "xenorchestra_vm" "vm" {
name_label = var.vm_name
name_description = var.description
template = var.template_uuid
cpus = var.cpus
memory_max = var.memory * 1024 * 1024
hvm_boot_firmware = "uefi"
auto_poweron = false
destroy_cloud_config_vdi_after_boot = true
power_state = "Running"
clone_type = "full"
disk {
sr_id = var.sr_uuid
name_label = "${var.vm_name}-osdisk"
size = var.disk_size * 1024 * 1024 * 1024
}
dynamic "disk" {
for_each = var.data_disks
content {
sr_id = var.sr_uuid
name_label = "${var.vm_name}-${disk.value.name}"
size = disk.value.size * 1024 * 1024 * 1024
}
}
network {
network_id = var.network_id
}
cloud_config = var.ip_address != "" ? data.template_file.cloud_config.rendered : null
cloud_network_config = var.ip_address != "" ? data.template_file.cloud_network_config.rendered : null
When I commented out the cloud_config line the vm is created without a disk.
Xensource.log also shows the following :
Oct 28 16:23:59 dacshyp001 xapi: [ info||11548 :::80|dispatch:VM.provision D:c4cf2cdf383f|taskhelper] task Async.VM.provision R:57a7bfeaacf3 forwarded (trackid=e7b951e8d29a4f9c673e51262f6144c9)
Oct 28 16:23:59 dacshyp001 xapi: [ info||11548 HTTPS 172.28.4.11->:::80|Async.VM.provision R:57a7bfeaacf3|xapi_vm_helpers] VM.set_is_a_template('false')
Oct 28 16:23:59 dacshyp001 xapi: [error||188 |xapi events D:596426783cc2|xenops] events_from_xapi: missing from the cache: [ ff4ff6a6-379a-4ec0-9dd2-ae28f8b6bc2c ]
Oct 28 16:23:59 dacshyp001 xapi: [error||188 |xapi events D:596426783cc2|xenops] events_from_xapi: missing from the cache: [ ff4ff6a6-379a-4ec0-9dd2-ae28f8b6bc2c ]
Running the following command:
[15:44 dacshyp002 ~]# xe vm-list uuid=ff4ff6a6-379a-4ec0-9dd2-ae28f8b6bc2c
uuid ( RO) : ff4ff6a6-379a-4ec0-9dd2-ae28f8b6bc2c
name-label ( RW): Control domain on host: dacshyp001
power-state ( RO): running
XOA commit 45ef6
I’m not sure where to start troubleshooting this, any help would be appreciated.
Thanks in advance,
Carlo