Automating XenServer® with Terraform
The XenServer Terraform Provider enables IT admins to automate configuration and management tasks for XenServer environments. This is especially useful in large-scale setups, where automation ensures consistency, reduces manual errors, and saves time. With the Terraform provider, you can:
- Create virtual machines (VMs)
- Manage snapshots (create and remove)
- Configure storage (add or remove local and NFS types)
- Set up and manage networks
- Retrieve information about XenServer hosts
Key benefits of the XenServer Terraform Provider:
- Automation: Simplifies the deployment and management of XenServer environments through Infrastructure-as-Code (IaC) practices.
- Efficiency: Automates tasks such as VM creation, snapshot management, and storage or network configuration, minimizing manual intervention.
- Consistency: Ensures uniform configurations across large environments, minimizing errors.
- Scalability: Supports rapid infrastructure growth by streamlining the creation and rebuilding of environments, such as QA setups.
Prerequisites
Before using the XenServer Terraform Provider, ensure that you have the following:
-
Terraform version 1.8 or higher
Download Terraform from the official Terraform Installation Guide.
Windows users can install Terraform using Chocolatey by running the following command:
choco install terraform <!--NeedCopy--> -
XenServer instance with administrative access
-
XenServer API credentials
These include the username, password, and the IP address of your XenServer.
Get started
-
Prepare the Terraform configuration.
To start, add the XenServer Terraform Provider to your Terraform configuration file
main.tf:terraform { required_providers { xenserver = { source = "xenserver/xenserver" } } } provider "xenserver" { host = "https://<ip address of XenServer>" username = "root" password = <root password> ca_cert_path = <path to cert.pem> # Required from version 0.3.0 } <!--NeedCopy--> -
Define resources.
For example, to create a VM, define the resource in your configuration file:
data "xenserver_sr" "sr" { name_label = "Local storage" } resource "xenserver_vdi" "vdi1" { name_label = "local-storage-vdi-1" sr_uuid = data.xenserver_sr.sr.data_items[0].uuid virtual_size = 100 * 1024 * 1024 * 1024 } data "xenserver_network" "network" {} resource "xenserver_vm" "windows_vm" { name_label = "Windows VM" template_name = "Windows 11" static_mem_max = 4 * 1024 * 1024 * 1024 vcpus = 4 cores_per_socket = 2 cdrom = "win11-x64_uefi.iso" boot_mode = "uefi_security" boot_order = "cdn" hard_drive = [ { vdi_uuid = xenserver_vdi.vdi1.uuid, bootable = true, mode = "RW" } ] network_interface = [ { device = "0" network_uuid = data.xenserver_network.network.data_items[0].uuid, } ] other_config = { "tf_created" = "true" } } <!--NeedCopy-->Or, to create an NFS Storage Repository (SR):
resource "xenserver_sr" "nfs" { name_label = "Test NFS SR" type = "nfs" content_type = "" shared = true device_config = { server = "192.0.2.1" serverpath = "/server/path" nfsversion = "3" } sm_config = { shared = "true" } } <!--NeedCopy--> -
Initialize and apply the configuration.
To install the XenServer Terraform Provider, run:
terraform init <!--NeedCopy-->Then, to provision the defined resources, run:
terraform apply <!--NeedCopy-->
For advanced configurations and additional resources, refer to the XenServer Terraform Provider Documentation. If you encounter any issues, contact Support or raise a GitHub issue ticket.
What’s new
The XenServer Terraform Provider is updated independently of XenServer versions to introduce new automation capabilities, fixes, and ensure ongoing compatibility.
XenServer Terraform Provider 0.3.0
Released Sep 8, 2026
This release contains the following security improvements:
- TLS certificate verification is now enabled by default. Set the
ca_cert_pathattribute to the path of your XenServer host’s CA certificate (PEM). For development or testing only, setinsecure = trueto skip verification. - All connections to the XenServer host now use HTTPS.
This release contains the following improvements:
- Release XenServer Terraform Provider with Go SDK v26.16.01.
This release contains fixes for the following issues:
- Resolve a network interface naming incompatibility that prevented name-based network resolution from working on XenServer 9 hosts.
Earlier releases
0.2.2
Released Mar 27, 2025
This release contains the following improvements:
- Update the XenServer Terraform Provider dependencies to fix a security advisory in an upstream package.
- Release XenServer Terraform Provider with Go SDK v25.3.0.
0.2.1
Released Jan 20, 2025
This release introduces the following new automation capabilities:
- Create a VM from a template with full disk copy.
This release contains the following improvements:
- Return UUIDs instead of internal references to improve usability.
This release contains fixes for the following issues:
- Creating, modifying, or destroying a pool can sometimes fail and exit the SSH command with an error.
0.2.0
Released Nov 11, 2024
This release introduces the following new automation capabilities:
- Add and remove hosts from pools with ease, improving scalability and simplifying maintenance.
- Update the default SR and management network.
- Create and delete SMB/CIFS storage, offering greater flexibility in storage configurations.
This release contains the following improvements:
- Remove the disk number limit when creating VMs, reducing hardware dependency and optimizing storage.
- Enable VMs to be reverted to snapshots, making recovery and rollback more straightforward.
- Enable credentials to be read from environment variables, simplifying configuration management.
0.1.2
Released Oct 31, 2024
This release contains fixes for the following issues:
- If you are using XenServer Terraform Provider version 0.1.1, you might encounter compatibility issues after applying the XenServer 8.4 updates released to Early Access on 25 September 2024 and Normal on 2 October 2024. Version 0.1.2 resolves these compatibility issues.