### Get VM CPU Information Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md This example shows how to retrieve the maximum and current number of CPUs for a VM using the `xo-cli` command and `jq` for JSON parsing. It illustrates how CPU updates might affect VM state. ```bash $xo-cli xo.getAllObjects filter='json:{"id": "cf7b5d7d-3cd5-6b7c-5025-5c935c8cd0b8"}' | jq '.[].CPUs' { "max": 4, "number": 2 } # Updating the VM to use 3 CPUs would happen without stopping/starting the VM # Updating the VM to use 5 CPUs would stop/start the VM ``` -------------------------------- ### Basic Cloud-Config Resource Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Defines a basic cloud-init configuration for VM provisioning. This example installs packages and sets up a user with SSH access. ```terraform # Basic cloud-config resource "xenorchestra_cloud_config" "basic" { name = "basic-linux-config" template = <<-EOF #cloud-config package_update: true package_upgrade: true packages: - vim - htop - curl users: - name: deploy sudo: ALL=(ALL) NOPASSWD:ALL shell: /bin/bash ssh_authorized_keys: - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ... deploy@example.com runcmd: - systemctl enable --now fail2ban EOF } ``` -------------------------------- ### Example Usage of xenorchestra_vms Data Source Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/vms.md This example demonstrates how to use the xenorchestra_vms data source to filter running VMs within a specific pool and then output a map of VM names to their maximum memory, as well as the total count of VMs found. ```terraform data "xenorchestra_pool" "pool" { name_label = "Your pool" } data "xenorchestra_vms" "vms" { pool_id = data.xenorchestra_pool.pool.id power_state = "Running" host = data.xenorchestra_pool.pool.master } output "vms_max_memory_map" { value = tomap({ for k, vm in data.xenorchestra_vms.vms.vms : k => vm.memory_max }) } output "vms_length" { value = length(data.xenorchestra_vms.vms.vms) } ``` -------------------------------- ### Create Xen Orchestra Networks Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/network.md Examples for creating a standard private network and a VLAN-tagged network using the xenorchestra_network resource. ```terraform data "xenorchestra_host" "host1" { name_label = "Your host" } # Create a single server network private network resource "xenorchestra_network" "private_network" { name_label = "new network name" pool_id = data.xenorchestra_host.host1.pool_id } # Create a network with a 22 VLAN tag from the eth0 device resource "xenorchestra_network" "vlan_network" { name_label = "new network name" pool_id = data.xenorchestra_host.host1.pool_id source_pif_device = "eth0" vlan = 22 } ``` -------------------------------- ### Create Bonded Network with PIFs Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/bonded_network.md This example demonstrates how to create a bonded network using standard PIFs. Ensure the PIFs are correctly identified and associated with the target host and pool. ```terraform data "xenorchestra_host" "host1" { name_label = "Your host" } data "xenorchestra_pif" "eth1" { device = "eth1" vlan = -1 host_id = data.xenorchestra_host.host1.id } data "xenorchestra_pif" "eth2" { device = "eth2" vlan = -1 host_id = data.xenorchestra_host.host1.id } # Create a bonded network from normal PIFs resource "xenorchestra_bonded_network" "network" { name_label = "new network name" bond_mode = "active-backup" pool_id = data.xenorchestra_host.host1.pool_id pif_ids = [ data.xenorchestra_pif.eth1.id, data.xenorchestra_pif.eth2.id, ] } ``` -------------------------------- ### Create a VM with Cloud-Config Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md This example demonstrates creating a VM with a custom cloud-config, utilizing Terraform's `templatefile` function for variable substitution. It requires pre-defined data sources for the pool, template, and network. ```hcl /* # cloud_config.tftpl file used by the cloudinit templating. #cloud-config hostname: ${hostname} fqdn: ${hostname}.${domain} package_upgrade: true */ # Content of the terraform files data "xenorchestra_pool" "pool" { name_label = "pool name" } data "xenorchestra_template" "template" { name_label = "Puppet agent - Bionic 18.04 - 1" } data "xenorchestra_network" "net" { name_label = "Pool-wide network associated with eth0" } 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 = "description" template = data.xenorchestra_template.template.id # 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 = "7f469400-4a2b-5624-cf62-61e522e50ea1" name_label = "Ubuntu Bionic Beaver 18.04_imavo" size = 32212254720 } tags = [ "Ubuntu", "Bionic", ] // Override the default create timeout from 5 mins to 20. timeouts { create = "20m" } // Note: Xen Orchestra populates values within Xenstore and will need ignored via // lifecycle ignore_changes or modeled in your terraform code xenstore = { key1 = "val1" key2 = "val2" } } ``` -------------------------------- ### Create a VM and Wait for IP Assignment Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md This example creates a VM with two network interfaces and configures it to wait until the first interface is assigned an IP address via DHCP within a specified CIDR block. It also defines required arguments like CPU, disk, memory, name, and template. ```hcl # vm resource that waits until its first network interface # is assigned an IP via DHCP resource "xenorchestra_vm" "vm" { # Specify VM with two network interfaces network { network_id = "7ed8998b-405c-40b5-b164-f9058efcf6b4" expected_ip_cidr = "10.0.0.0/16" } network { network_id = "b4cf8532-ae43-493b-9fc6-a6b456d16876" } # required arguments for xenorchestra_vm cpus = 2 disk { sr_id = "7f469400-4a2b-5624-cf62-61e522e50ea1" name_label = "Ubuntu Bionic Beaver 18.04_imavo" size = 32212254720 } memory_max = 1073733632 name_label = "Name" template = data.xenorchestra_template.template.id } output "first-network-interface-ips" { value = xenorchestra_vm.vm.network[0].ipv4_addresses } ``` -------------------------------- ### Create VM with Cloud-Config Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt This resource creates a virtual machine (`xenorchestra_vm`) and applies a cloud-init configuration, retrieved using the `xenorchestra_cloud_config` data source, during its creation for initial setup. ```terraform # Use the cloud config in a VM resource "xenorchestra_vm" "configured_vm" { name_label = "pre-configured-vm" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id cloud_config = data.xenorchestra_cloud_config.base_config.template network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "system-disk" size = 32212254720 } } ``` -------------------------------- ### Create Bonded Network (VLAN-Tagged) Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Sets up a bonded network using VLAN-tagged physical interfaces. This example uses 'balance-slb' mode for load balancing. ```terraform # Create a bonded network from VLAN-tagged PIFs data "xenorchestra_pif" "eth1_vlan" { device = "eth1" vlan = 200 host_id = data.xenorchestra_host.host.id } data "xenorchestra_pif" "eth2_vlan" { device = "eth2" vlan = 200 host_id = data.xenorchestra_host.host.id } resource "xenorchestra_bonded_network" "storage_network" { name_label = "storage-bonded-vlan200" pool_id = data.xenorchestra_host.host.pool_id bond_mode = "balance-slb" pif_ids = [ data.xenorchestra_pif.eth1_vlan.id, data.xenorchestra_pif.eth2_vlan.id, ] } ``` -------------------------------- ### Create Bonded Network with VLAN PIFs Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/bonded_network.md This example shows how to create a bonded network using PIFs that are configured on specific VLANs. This is useful for segmenting network traffic. ```terraform data "xenorchestra_host" "host1" { name_label = "Your host" } data "xenorchestra_pif" "eth1_vlan" { device = "eth1" vlan = 15 host_id = data.xenorchestra_host.host1.id } data "xenorchestra_pif" "eth2_vlan" { device = "eth2" vlan = 15 host_id = data.xenorchestra_host.host1.id } # Create a bonded network from normal PIFs resource "xenorchestra_bonded_network" "network_vlan" { name_label = "new network name" bond_mode = "active-backup" pool_id = data.xenorchestra_host.host1.pool_id pif_ids = [ data.xenorchestra_pif.eth1_vlan.id, data.xenorchestra_pif.eth2_vlan.id, ] } ``` -------------------------------- ### GET /data/xenorchestra_cloud_config Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/cloud_config.md Retrieves details for a specific cloud configuration based on the provided name. ```APIDOC ## GET xenorchestra_cloud_config ### Description Provides information about a cloud config resource. Note that names must be unique to prevent lookup failures. ### Parameters #### Required - **name** (String) - Required - The name of the cloud config to look up. ### Response #### Read-Only Fields - **id** (String) - The ID of the cloud config resource. - **template** (String) - The contents of the cloud-config. ### Request Example ```terraform data "xenorchestra_cloud_config" "cloud_config" { name = "Name of cloud config" } ``` ``` -------------------------------- ### Use ISO VDI with VM Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Attaches an uploaded ISO file (as a VDI) to a virtual machine's CD-ROM drive. This is typically used for OS installation. ```terraform # Use the uploaded ISO with a VM resource "xenorchestra_vm" "installer" { name_label = "ubuntu-installer" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.other.id # Use a generic template # Attach the ISO as a CD-ROM cdrom { id = xenorchestra_vdi.ubuntu_iso.id } network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "ubuntu-system" size = 53687091200 } } ``` -------------------------------- ### Example Usage of xenorchestra_cloud_config Data Source Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/cloud_config.md Use this data source to retrieve information about a cloud config. Ensure that the name provided is unique to avoid Terraform failures. ```terraform data "xenorchestra_cloud_config" "cloud_config" { name = "Name of cloud config" } ``` -------------------------------- ### Create an ACL for a User on a Pool Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/acl.md This example demonstrates how to create an ACL entry. It first fetches the pool and user IDs using data sources, then assigns 'operator' action to the user on the specified pool. Ensure the pool and user exist and their IDs are correctly referenced. ```terraform data "xenorchestra_pool" "pool" { name_label = "Your pool" } data "xenorchestra_user" "user" { username = "my-username" } resource "xenorchestra_acl" "acl" { subject = data.xenorchestra_user.user.id object = data.xenorchestra_pool.pool.id action = "operator" } ``` -------------------------------- ### GET xenorchestra_sr Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/sr.md Retrieves details for a specific storage repository. Note that the lookup must result in a unique match to avoid errors. ```APIDOC ## GET xenorchestra_sr ### Description Provides information about a Storage repository to ease the lookup of VM storage information. ### Parameters #### Required - **name_label** (String) - Required - The name of the storage repository to look up #### Optional - **pool_id** (String) - Optional - The Id of the pool the storage repository exists on. - **tags** (Set of String) - Optional - The tags (labels) applied to the given entity. Not used for filtering if empty. ### Response #### Read-Only Fields - **container** (String) - The storage container. - **id** (String) - The ID of this resource. - **physical_usage** (Number) - The physical storage size. - **size** (Number) - The storage size. - **sr_type** (String) - The type of storage repository (lvm, udev, iso, user, etc). - **usage** (Number) - The current usage for this storage repository. - **uuid** (String) - uuid of the storage repository. This is equivalent to the id. ``` -------------------------------- ### Use Networks in a VM Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Attaches a virtual machine to previously defined networks. This example shows a VM connected to both an internal and a DMZ network. ```terraform resource "xenorchestra_vm" "app_server" { name_label = "app-server" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id network { network_id = xenorchestra_network.internal.id } network { network_id = xenorchestra_network.dmz.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "app-server-disk" size = 32212254720 } } ``` -------------------------------- ### Create VM with VDI as CD-ROM Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt This resource demonstrates creating a virtual machine (`xenorchestra_vm`) and attaching a VDI, retrieved via the `xenorchestra_vdi` data source, as its CD-ROM drive. ```terraform resource "xenorchestra_vm" "installer" { name_label = "os-installer" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.other.id cdrom { id = data.xenorchestra_vdi.ubuntu_iso.id } network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "system-disk" size = 53687091200 } } ``` -------------------------------- ### GET xenorchestra_network Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/network.md Retrieves details about a network in a XenServer pool using its name label and optional filters. ```APIDOC ## GET xenorchestra_network ### Description Provides information about a network of a Xenserver pool. Note: If there are multiple networks with the same name, the provider will fail. Ensure that your network, pool_id and other arguments identify a unique network. ### Parameters #### Required - **name_label** (String) - The name of the network. #### Optional - **bridge** (String) - The name of the bridge network interface. - **pool_id** (String) - The pool the network is associated with. ### Response #### Read-Only - **id** (String) - The ID of this resource. ``` -------------------------------- ### GET xenorchestra_user Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/user.md Retrieves details for a specific Xen Orchestra user. Use the search_in_session parameter if the authenticated user is not an administrator. ```APIDOC ## GET xenorchestra_user ### Description Provides information about a Xen Orchestra user. If the Xen Orchestra user account you are using is not an admin, see the search_in_session parameter. ### Method GET ### Endpoint xenorchestra_user ### Parameters #### Required - **username** (String) - Required - The username of the XO user. #### Optional - **search_in_session** (Boolean) - Optional - A boolean which will search for the user in the current session (session.getUser Xen Orchestra RPC call). This allows a non admin user to look up their own user account. ### Request Example ```terraform data "xenorchestra_user" "user" { username = "my-username" } ``` ### Response #### Read-Only - **id** (String) - The ID of this resource. ``` -------------------------------- ### Running the Full Test Suite Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/CONTRIBUTING.md Execute the entire test suite for the XenOrchestra Terraform provider, including both client integration and acceptance tests, by running 'make test'. ```bash # This runs the testclient and testacc Makefile targets make test ``` -------------------------------- ### Create XenOrchestra Virtual Machine Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Create a virtual machine with cloud-init, multiple disks, and network configuration. Supports advanced options like affinity, boot firmware, and Xenstore key-value pairs. Use data sources to look up pool, template, network, and storage information. ```terraform # Look up required data sources data "xenorchestra_pool" "pool" { name_label = "production-pool" } data "xenorchestra_template" "ubuntu" { name_label = "Ubuntu 22.04 LTS" pool_id = data.xenorchestra_pool.pool.id } data "xenorchestra_network" "management" { name_label = "Pool-wide network associated with eth0" } data "xenorchestra_sr" "storage" { name_label = "Local Storage" pool_id = data.xenorchestra_pool.pool.id } # Create cloud-init configuration resource "xenorchestra_cloud_config" "web_server" { name = "web-server-config" template = templatefile("${path.module}/cloud-config.tftpl", { hostname = "web-server-01" domain = "example.com" }) } # Create the virtual machine resource "xenorchestra_vm" "web_server" { name_label = "web-server-01" name_description = "Production web server" cpus = 4 memory_max = 8589934592 # 8 GB in bytes template = data.xenorchestra_template.ubuntu.id cloud_config = xenorchestra_cloud_config.web_server.template # Prefer to run on the pool master affinity_host = data.xenorchestra_pool.pool.master # Primary network interface with IP waiting network { network_id = data.xenorchestra_network.management.id expected_ip_cidr = "10.0.0.0/16" # Wait for DHCP IP in this range } # System disk disk { sr_id = data.xenorchestra_sr.storage.id name_label = "web-server-01-system" size = 53687091200 # 50 GB in bytes } # Data disk disk { sr_id = data.xenorchestra_sr.storage.id name_label = "web-server-01-data" size = 107374182400 # 100 GB in bytes } tags = ["production", "web", "ubuntu"] auto_poweron = true high_availability = "restart" power_state = "Running" # Boot configuration hvm_boot_firmware = "uefi" secure_boot = true # Custom timeouts timeouts { create = "30m" delete = "10m" } # Xenstore key-value pairs xenstore = { environment = "production" role = "web-server" } } # Output the VM's IP addresses output "web_server_ip" { value = xenorchestra_vm.web_server.network[0].ipv4_addresses } output "web_server_id" { value = xenorchestra_vm.web_server.id } ``` -------------------------------- ### Setting Up Environment Variables for Testing Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/CONTRIBUTING.md Source these environment variables from a file to configure the test environment for the XenOrchestra Terraform provider. Ensure all required variables are set correctly before running tests. ```bash # See the contents of ~/.xoa $ cat ~/.xoa export XOA_URL=ws://yourdomain.com export XOA_USER=username export XOA_PASSWORD=password export XOA_POOL=pool-1 export XOA_TEMPLATE='Debian 10 Cloudinit' [ ... ] # Source the environment variables inside the file eval $(cat ~/.xoa) ``` -------------------------------- ### Create VM from Template Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Provisions a new virtual machine using a specified template, configuring its name, CPUs, memory, network, and disk. ```terraform resource "xenorchestra_vm" "from_template" { name_label = "vm-from-template" template = data.xenorchestra_template.ubuntu.id cpus = 2 memory_max = 4294967296 network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "system-disk" size = 32212254720 } } ``` -------------------------------- ### Get Running VMs in a Pool Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Retrieves all VMs currently in a running state within a specified Xen Orchestra pool. Requires the pool ID. ```terraform data "xenorchestra_vms" "running" { pool_id = data.xenorchestra_pool.pool.id power_state = "Running" } ``` -------------------------------- ### Get xenorchestra_resource_set Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/resource_set.md Use this data source to retrieve information about a specific resource set by its name. Terraform will fail if multiple resource sets share the same name. ```terraform data "xenorchestra_resource_set" "rs" { name = "my resource set" } ``` -------------------------------- ### Redirect Provider Logs to File Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/README.md Configure both the log level and the output file path to persist logs for later analysis. ```bash export TF_LOG_PROVIDER=DEBUG export TF_LOG_PATH=./terraform.log terraform apply ``` -------------------------------- ### Configure Xen Orchestra Resource Sets Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Create resource sets to enforce quotas on CPU, memory, and disk usage for specific user groups. ```terraform data "xenorchestra_template" "template" { name_label = "Ubuntu 22.04 LTS" } data "xenorchestra_sr" "storage" { name_label = "Local Storage" } data "xenorchestra_pif" "eth0" { device = "eth0" vlan = -1 } data "xenorchestra_user" "team_lead" { username = "team-lead@example.com" } data "xenorchestra_user" "developer" { username = "developer@example.com" } # Create a resource set with quotas resource "xenorchestra_resource_set" "dev_team" { name = "development-team-resources" # Users who can access this resource set subjects = [ data.xenorchestra_user.team_lead.id, data.xenorchestra_user.developer.id, ] # Objects available in this resource set objects = [ data.xenorchestra_template.template.id, data.xenorchestra_sr.storage.id, data.xenorchestra_pif.eth0.network, ] # CPU limit: 20 cores limit { type = "cpus" quantity = 20 } # Memory limit: 64 GB limit { type = "memory" quantity = 68719476736 } # Disk limit: 500 GB limit { type = "disk" quantity = 536870912000 } } ``` -------------------------------- ### CD-ROM Configuration Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md Configures the CD-ROM device for a VM, specifying the ISO image to attach. ```APIDOC ## Nested Schema for `cdrom` ### Description Configuration for attaching an ISO image to a VM's CD-ROM drive. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (String) - Required - The ID of the ISO (VDI) to attach to the VM. This can be easily provided by using the `vdi` data source. ``` -------------------------------- ### Get VMs Running on a Specific Host Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Filters running VMs to only include those on the master host of a Xen Orchestra pool. Requires pool ID and master host information. ```terraform data "xenorchestra_vms" "on_master" { pool_id = data.xenorchestra_pool.pool.id power_state = "Running" host = data.xenorchestra_pool.pool.master } ``` -------------------------------- ### Get Xen Orchestra User Information Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/user.md Use this data source to fetch details of a Xen Orchestra user by their username. For non-admin users, set `search_in_session` to true to search within the current session. ```terraform data "xenorchestra_user" "user" { username = "my-username" } ``` -------------------------------- ### Output VM Details Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Generates a list of detailed information for each running VM, including name, CPUs, memory in GB, and IP addresses. ```terraform output "vm_details" { value = [ for vm in data.xenorchestra_vms.running.vms : { name = vm.name_label cpus = vm.cpus memory_gb = vm.memory_max / 1073741824 ip_addresses = vm.ipv4_addresses } ] } ``` -------------------------------- ### Import a Xen Orchestra resource set Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/resource_set.md Uses the terraform import command to bring an existing resource set into state management. ```shell # ID can be found from the following command: # $ xo-cli resourceSet.getAll $ terraform import xenorchestra_resource_set.rs MGSpuwnbtUE ``` -------------------------------- ### Get xenorchestra_host Data Source Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/data-sources/host.md Use this data source to retrieve information about a host by its name label. Ensure the name label is unique to avoid Terraform failures. The host ID can then be used for VM affinity. ```terraform data "xenorchestra_host" "host1" { name_label = "Your host" } resource "xenorchestra_vm" "node" { //... affinity_host = data.xenorchestra_host.host1.id //... } ``` -------------------------------- ### Output VM Template Information Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Outputs key identifiers and boot firmware information for a retrieved VM template. ```terraform output "template_info" { value = { id = data.xenorchestra_template.ubuntu.id uuid = data.xenorchestra_template.ubuntu.uuid boot_firmware = data.xenorchestra_template.ubuntu.boot_firmware } } ``` -------------------------------- ### Use Cloud-Config in a VM Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Deploys a virtual machine using a pre-defined cloud-init configuration. The `cloud_config` argument accepts the rendered template content. ```terraform # Use the cloud-config in a VM resource "xenorchestra_vm" "server" { name_label = "configured-server" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id cloud_config = xenorchestra_cloud_config.templated.template network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "server-disk" size = 32212254720 } } ``` -------------------------------- ### Upload ISO File as VDI Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Creates a Virtual Disk Image (VDI) resource and uploads a local ISO file to a specified Xen Orchestra storage repository. Ensure the `filepath` points to the correct ISO location. ```terraform data "xenorchestra_sr" "iso_storage" { name_label = "ISO Storage" } # Upload an ISO file resource "xenorchestra_vdi" "ubuntu_iso" { name_label = "ubuntu-22.04-server" sr_id = data.xenorchestra_sr.iso_storage.id filepath = "${path.module}/isos/ubuntu-22.04-live-server-amd64.iso" type = "raw" } ``` -------------------------------- ### Create a Xen Orchestra resource set Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/resource_set.md Defines a resource set with specific user subjects, object scopes, and resource limits. ```terraform data "xenorchestra_template" "template" { name_label = "Ubuntu Bionic Beaver 18.04" } data "xenorchestra_sr" "sr" { name_label = "Your storage repository label" } data "xenorchestra_pif" "eth0" { device = "eth0" vlan = -1 } data "xenorchestra_user" "user" { username = "test_user" } resource "xenorchestra_resource_set" "rs" { name = "new-resource-set" subjects = [ data.xenorchestra_user.user.id, ] objects = [ data.xenorchestra_template.template.id, data.xenorchestra_sr.sr.id, data.xenorchestra_pif.eth0.network, ] limit { type = "cpus" quantity = 20 } limit { type = "disk" quantity = 107374182400 } limit { type = "memory" quantity = 12884901888 } } ``` -------------------------------- ### Retrieve and Use Multiple Xen Orchestra Hosts Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Fetch a list of hosts to perform bulk operations or distribute VM deployments across a pool. ```terraform data "xenorchestra_pool" "pool" { name_label = "production-pool" } data "xenorchestra_hosts" "all_hosts" { pool_id = data.xenorchestra_pool.pool.id sort_by = "name_label" sort_order = "asc" tags = ["compute"] # Optional tag filtering } # Create one VM per host for distributed deployment resource "xenorchestra_vm" "distributed" { count = length(data.xenorchestra_hosts.all_hosts.hosts) name_label = "distributed-vm-${count.index + 1}" affinity_host = data.xenorchestra_hosts.all_hosts.hosts[count.index].id cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "distributed-vm-${count.index + 1}-disk" size = 32212254720 } } output "host_count" { value = length(data.xenorchestra_hosts.all_hosts.hosts) } output "pool_master" { value = data.xenorchestra_hosts.all_hosts.master } ``` -------------------------------- ### Manage Xen Orchestra ACLs Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt This resource (`xenorchestra_acl`) demonstrates how to manage Access Control Lists (ACLs) by associating a user (retrieved via `xenorchestra_user` data source) with specific actions on a resource. ```terraform # Use in ACL resource "xenorchestra_acl" "dev_access" { subject = data.xenorchestra_user.developer.id object = xenorchestra_vm.dev_server.id action = "operator" } ``` -------------------------------- ### Associate VM with Resource Set Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt This resource creates a virtual machine (`xenorchestra_vm`) and associates it with a specific resource set, identified using the `xenorchestra_resource_set` data source. This is useful for quota management and access control. ```terraform # Associate a VM with the resource set resource "xenorchestra_vm" "dev_vm" { name_label = "development-vm" resource_set = data.xenorchestra_resource_set.dev_resources.id cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id network { network_id = data.xenorchestra_network.management.id } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "dev-disk" size = 32212254720 } } ``` -------------------------------- ### VM Optional Attributes Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/vm.md This section details the optional attributes that can be configured for a VM resource. ```APIDOC ## VM Optional Attributes ### Description Configuration options for a Virtual Machine that are not strictly required for its creation. ### Parameters #### Optional - `affinity_host` (String) - The preferred host for the VM. Changing this requires a VM reboot. - `auto_poweron` (Boolean) - Whether the VM should automatically power on. Defaults to `false`. - `blocked_operations` (Set of String) - A list of operations that are not permitted on the VM. See XenAPI documentation for a full list. - `cdrom` (Block List, Max: 1) - Configuration for attaching an ISO to the VM for OS installation. - `clone_type` (String) - The type of clone to perform (`fast` or `full`). Defaults to `fast`. - `cloud_config` (String) - The content of the cloud-init configuration for the VM. - `cloud_network_config` (String) - The content of the cloud-init network configuration for the VM. - `core_os` (Boolean) - Boolean parameter for core OS settings. - `cpu_cap` (Number) - CPU capping value for the VM. - `cpu_weight` (Number) - CPU weight for the VM. - `destroy_cloud_config_vdi_after_boot` (Boolean) - Whether to destroy the cloud config VDI after boot. Defaults to `false`. - `exp_nested_hvm` (Boolean) - Enables nested virtualization for the VM. - `high_availability` (String) - The restart priority for the VM (`best-effort`, `restart`, or empty string for no restarts). Defaults to empty string. - `host` (String) - The host on which the VM should run. - `hvm_boot_firmware` (String) - The firmware to use for the VM (`bios` or `uefi`). - `installation_method` (String) - The installation method for the VM (e.g., `network` for PXE boot). Cannot be used with `cdrom`. - `memory_min` (Number) - The minimum amount of memory in bytes for the VM. Set equal to `memory_max` for static memory. - `name_description` (String) - A description for the VM. - `power_state` (String) - The desired power state of the VM (`Running`, `Halted`, `Paused`, `Suspended`). - `resource_set` (String) - The resource set to assign the VM to. - `secure_boot` (Boolean) - Enables UEFI secure boot for the VM. - `start_delay` (Number) - Delay in seconds before starting the VM. - `tags` (Set of String) - Tags (labels) to apply to the VM. - `timeouts` (Block, Optional) - Timeout configuration for operations. - `vga` (String) - The video adapter to use (`std` or `cirrus`). - `videoram` (Number) - The amount of videoram in MB for the VM. - `xenstore` (Map of String) - Key-value pairs to be populated in XenStore. ``` -------------------------------- ### Create VM Using PIF's Network Source: https://context7.com/vatesfr/terraform-provider-xenorchestra/llms.txt Provisions a VM and configures its network interface to use the network associated with a specific physical network interface (PIF). ```terraform resource "xenorchestra_vm" "server" { name_label = "server" cpus = 2 memory_max = 4294967296 template = data.xenorchestra_template.ubuntu.id network { network_id = data.xenorchestra_pif.eth0.network } disk { sr_id = data.xenorchestra_sr.storage.id name_label = "system-disk" size = 32212254720 } } ``` -------------------------------- ### Define a Xen Orchestra cloud config resource Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/cloud_config.md Use this resource to define a cloud-init configuration that can be assigned to a virtual machine. ```terraform resource "xenorchestra_cloud_config" "demo" { name = "cloud config name" template = < # Or set XOA_INSECURE environment variable to any value } provider "xenorchestra_token_auth" { # XOA_USER and XOA_PASSWORD cannot be set, nor can their arguments token = "" # or set XOA_TOKEN environment variable } ``` -------------------------------- ### xenorchestra_cloud_config Resource Source: https://github.com/vatesfr/terraform-provider-xenorchestra/blob/master/docs/resources/cloud_config.md Defines the schema and usage for the xenorchestra_cloud_config resource. ```APIDOC ## Resource: xenorchestra_cloud_config ### Description Creates a Xen Orchestra cloud config resource used for cloud-init configurations. ### Schema #### Required - **name** (String) - Required - The name of the cloud config. - **template** (String) - Required - The cloud init config content. #### Read-Only - **id** (String) - The ID of this resource. ### Example Usage ```terraform resource "xenorchestra_cloud_config" "demo" { name = "cloud config name" template = <