XenServer

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

  1. 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>
    }
    <!--NeedCopy-->
    
  2. 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-->
    
  3. 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_path attribute to the path of your XenServer host’s CA certificate (PEM). For development or testing only, set insecure = true to 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.
Automating XenServer® with Terraform