vatesfr / terraform-provider-xenorchestra

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

Add iso support to the xenorcestra_vm resource so VMs can be installed on diskless templates #108

Closed ddelnano closed 3 years ago

ddelnano commented 3 years ago

This is related to #39 but I decided to create a new issue specifically focused on adding iso support

ddelnano commented 3 years ago

While testing how this would work, I was able to create a VM from a diskless template with the following command

ddelnano@ddelnano-desktop:~/code/xen-orchestra$ xo-cli vm.create bootAfterCreate=true name_label="Terraform with iso" template='OpaqueRef:f5ebd5b7-465c-487c-acc2-5f2f412ebd23' VIFs=json:'[{"network": "41260326-d78
3-f850-f16f-ac55d6b03cf0"}]' installation=json:'{"method":"cdrom", "repository": "52219efd-386e-49a5-9a7b-bfd68c36fc85"}' VDIs=json:'[{"size": 10000000000, "SR":"86a9757d-9c05-9fe0-e79a-8243cb1f37f3", "type": "sys
tem"}]'
d1aa053c-06bc-4882-eb17-7b35a6ab5792

The VM then booted to the ISO installation menu.

Screenshot_20210219_000228

So we will need the terraform provider to make a similar request on VM creation.

ddelnano commented 3 years ago

Using this functionality would look something like this. The cdrom block might need more thought but we will definitely need a VDI data source.

data "xenorchestra_vdi" "bionic_iso" {
  name_label = "ubuntu-16.04.6-server-amd64iso"
  pool_id = data.xenorchestra_pool.pool.id
}

resource "xenorchestra_vm" "vm" {
  ...
  ...
  disk {
    sr_id = "xxxxxx"
    size = 10
  }
  cdrom {
    vdi_id = data.xenorchestra_vdi.bionic_iso.id
  }
}
ddelnano commented 3 years ago

This is now working in v0.16.0 of the provider. See the docs on terraform registry for more details!