XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Xen-Orchestra Terraform provider and Windows

    Scheduled Pinned Locked Moved Infrastructure as Code
    34 Posts 7 Posters 8.6k Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • florentF Offline
      florent Vates 🪐 XO Team @rochemike
      last edited by

      @rochemike great, that will be even easier

      can you open a support ticket and open a support tunnel ? I will connect and patch your installation

      R 1 Reply Last reply Reply Quote 2
      • R Offline
        rochemike @florent
        last edited by

        @florent ticket opened!

        florentF 2 Replies Last reply Reply Quote 0
        • florentF Offline
          florent Vates 🪐 XO Team @rochemike
          last edited by

          @rochemike patch done this morning

          1 Reply Last reply Reply Quote 2
          • florentF Offline
            florent Vates 🪐 XO Team @rochemike
            last edited by

            @rochemike hi mike did you have time to test ?

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              rochemike @florent
              last edited by rochemike

              @florent hello, I'm sorry for the delay.

              Yes, and I'm getting errors.

              right after "terraform apply" and answering "yes" to the prompt, I got this:

              xenorchestra_vm.rbbmspcs2: Creating...
              ā•·
              │ Error: jsonrpc2: code 10 message: invalid parameters: {"errors":[{"instancePath":"/affinityHost","schemaPath":"#/properties/affinityHost/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"},{"instancePath":"/VIFs/0/mac","schemaPath":"#/properties/VIFs/items/properties/mac/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"}]}
              │
              │   with xenorchestra_vm.rbbmspcs2,
              │   on vm.tf line 19, in resource "xenorchestra_vm" "rbbmspcs2":
              │   19: resource "xenorchestra_vm" "rbbmspcs2" {
              │
              ╵
              

              So... I did some Googling and found that another person was experiencing a similar issue recently, so I added the following line to my tf file:

              affinity_host = data.xenorchestra_pool.pool.master
              

              Now, I'm getting this error - and I can't figure out a solution on my own. Any ideas? I haven't toyed with my TF files in months, ever since I reported this, and wasn't getting these errors back then.

              xenorchestra_vm.rbbmspcs2: Creating...
              ā•·
              │ Error: jsonrpc2: code 10 message: invalid parameters: {"errors":[{"instancePath":"/VIFs/0/mac","schemaPath":"#/properties/VIFs/items/properties/mac/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"}]}
              │
              │   with xenorchestra_vm.rbbmspcs2,
              │   on vm-windows.tf line 19, in resource "xenorchestra_vm" "rbbmspcs2":
              │   19: resource "xenorchestra_vm" "rbbmspcs2" {
              │
              ╵
              

              Here follows the simplified TF file I've been using, with the new "affinity_host" line:

              data "xenorchestra_pool" "pool" {
                name_label = "b500-2555 Server Room"
              }
              
              data "xenorchestra_template" "vm_template" {
                name_label = "rbbmswsoe2019s_2023-02-28"
              }
              
              data "xenorchestra_sr" "sr" {
                name_label = "nfs-isilon-xcpng-b500-2555"
                pool_id = data.xenorchestra_pool.pool.id
              }
              
              data "xenorchestra_network" "network" {
                name_label = "VLAN113"
                pool_id = data.xenorchestra_pool.pool.id
              }
              
              resource "xenorchestra_vm" "rbbmspcs2" {
                memory_max = 8589934594
                cpus = 2
                name_label = "XO terraform tutorial"
                affinity_host = data.xenorchestra_pool.pool.master
                template = data.xenorchestra_template.vm_template.id
              
                network {
                  network_id = data.xenorchestra_network.network.id
                }
              
                disk {
                  sr_id = data.xenorchestra_sr.sr.id
                  name_label = "VM boot drive"
                  size = 50212254720
                }
              }
              
              G 1 Reply Last reply Reply Quote 0
              • G Offline
                gsrfan01
                last edited by gsrfan01

                What is your version of XO? There was a breaking change a few months back that required a MAC address to be defined but was changed. It's fixed now so if you update to the latest version it would fix it.

                Though I can't find it now, I remember having to roll back a version until it was fixed. Might be mixing this up with the affinity host actually...

                In case this is useful, here is my ubuntu TF

                data "xenorchestra_pool" "pool" {
                    name_label = var.pool_name
                }
                
                data "xenorchestra_template" "template" {
                    name_label = var.vmtemplate
                }
                
                data "xenorchestra_network" "net" {
                  name_label = var.network
                  pool_id = var.pool_uuid
                }
                
                resource "xenorchestra_cloud_config" "bar" {
                  name = "cloud config name"
                  # Template the cloudinit if needed
                  template = templatefile("cloud_config.tftpl", {
                    hostname = var.hostname
                  })
                }
                
                resource "xenorchestra_cloud_config" "net" {
                  name = "cloud network config name"
                  # Template the cloudinit if needed
                  template = templatefile("cloud_network_config.tftpl", {
                  })
                }
                
                
                resource "xenorchestra_vm" "bar" {
                    memory_max = var.ram
                    cpus  = var.cpus
                    cloud_config = xenorchestra_cloud_config.bar.template
                    cloud_network_config = xenorchestra_cloud_config.net.template
                    name_label = var.name_label
                    name_description = var.name_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 = var.disk_sr
                      name_label = var.disk_name
                      size = var.disk_size 
                    }
                
                    tags = [
                      "Nightly Backup"
                    ]
                
                    wait_for_ip = true
                
                    // Override the default create timeout from 5 mins to 20.
                    timeouts {
                      create = "20m"
                    }
                }
                
                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  rochemike @gsrfan01
                  last edited by

                  @gsrfan01 I'm up-to-date as far as I can tell.

                  Current version: 5.84.0

                  I just want to build a VM to test another feature - what can I do to get past this message? I can't find a way to define VIFs in Terraform for XO.

                  1 Reply Last reply Reply Quote 0
                  • G Offline
                    gsrfan01 @rochemike
                    last edited by

                    I'm wondering if it's because there is no pool UUID specified in your config.

                    Working bottom up we have your network which references the xenorchestra_network object

                    network {
                        network_id = data.xenorchestra_network.network.id
                    }
                    

                    Which is this, specifying the network name and references xenorchestra_pool for the pool information

                    data"xenorchestra_network""network" {
                      name_label = "VLAN113"
                      pool_id = data.xenorchestra_pool.pool.id
                    }
                    

                    Which specifies the name of the pool.

                    data"xenorchestra_pool""pool" {
                       name_label = "b500-2555 Server Room"
                    }
                    

                    My config has the name of the network and the UUID of the pool that network resides on. I tried swapping it over to the pool name and my script errors out at applying the terraform configuration, swapping it over to the UUID of the pool worked though.

                    data "xenorchestra_network" "net" {
                    
                      name_label = var.network. 
                      pool_id = var.pool_uuid
                    
                    }
                    
                    R 1 Reply Last reply Reply Quote 0
                    • R Offline
                      rochemike @gsrfan01
                      last edited by rochemike

                      @gsrfan01

                      I updated that stanza as follows

                      data "xenorchestra_network" "network" {
                        name_label = "VLAN113"
                        pool_id = var.pool_uuid
                      }
                      

                      Now I can't get past "terraform plan" because "pool_uuid" hasn't been declared.

                      ā•·
                      │ Error: Reference to undeclared input variable
                      │
                      │   on vm.tf line 16, in data "xenorchestra_network" "network":
                      │   16:   pool_id = var.pool_uuid
                      │
                      │ An input variable with the name "pool_uuid" has not been declared. This variable can be declared with a variable "pool_uuid" {} block.
                      ╵
                      

                      No amount of googling is helping me to figure out how to declare "var.pool_uuid"

                      G 1 Reply Last reply Reply Quote 0
                      • G Offline
                        gsrfan01 @rochemike
                        last edited by

                        @rochemike Sorry that's on me, you want to set the UUID like below, replace YOUR_POOL_UUID with the pool UUID, make sure it stays wrapped in quotes.

                        data "xenorchestra_network" "net" {
                          name_label = var.network
                          pool_id = "YOUR_POOL_UUID"
                        }
                        
                        

                        I set mine as a variable during an Ansible playbook that writes it to a terraform.tfvars file providing the var.pool_uuid alongside others.

                        R 1 Reply Last reply Reply Quote 0
                        • R Offline
                          rochemike @gsrfan01
                          last edited by

                          @gsrfan01

                          so you're saying paste in the literal UUID

                          pool_id = "d27d1ac8-696a-78c6-e44e-444d1d10b5bb"
                          

                          instead of referencing it like this?

                          pool_id = data.xenorchestra_pool.pool.id
                          

                          This referenced version worked just fine in March... do I now have to change every instance of this pool_id definition thoughout my TF file?

                          G 1 Reply Last reply Reply Quote 0
                          • G Offline
                            gsrfan01 @rochemike
                            last edited by

                            @rochemike Based on the TF snippet that you pasted earlier you're declaring the pool's name but not the UUID. The pool_id in xenorchestra_network needs to be the UUID to work. I tried both the name and the UUID on my end and failed with the name but worked with the UUID.

                            data "xenorchestra_pool" "pool" {
                              name_label = "b500-2555 Server Room"
                            }
                            ...
                            data "xenorchestra_network" "network" {
                              name_label = "VLAN113" 
                              pool_id = data.xenorchestra_pool.pool.id
                            }
                            ...
                              network {
                                network_id = data.xenorchestra_network.network.id
                              }
                            ...
                            }
                            

                            You may be able to skip the pool_id entirely based on the Terrafarm docs. This seems to work on my end.

                            That would look like the below assuming you don't have VLAN113 on another pool visible to Xen Orchestra.

                            data "xenorchestra_network" "net" {
                              name_label = "VLAN113"
                            }
                            
                            R 1 Reply Last reply Reply Quote 0
                            • R Offline
                              rochemike @gsrfan01
                              last edited by

                              @gsrfan01

                              Here is my current vm.tf file

                              data "xenorchestra_pool" "pool" {
                                name_label = "b500-2555 Server Room"
                              }
                              
                              data "xenorchestra_template" "vm_template" {
                                name_label = "rbbmswsoe2019s_2023-02-28"
                              }
                              
                              data "xenorchestra_sr" "sr" {
                                name_label = "nfs-isilon-xcpng-b500-2555"
                                 pool_id = "d27d1ac8-696a-78c6-e44f-444d1d10b5aa"
                              #  pool_id = data.xenorchestra_pool.pool.id
                              }
                              
                              data "xenorchestra_network" "network" {
                                name_label = "VLAN113"
                                 pool_id = "d27d1ac8-696a-78c6-e44f-444d1d10b5aa"
                              #  pool_id = data.xenorchestra_pool.pool.id
                              }
                              
                              resource "xenorchestra_vm" "rbbmspcs2" {
                                memory_max = 8589934594
                                cpus = 2
                                name_label = "XO terraform tutorial"
                                affinity_host = data.xenorchestra_pool.pool.master
                                template = data.xenorchestra_template.vm_template.id
                              
                                network {
                                  network_id = data.xenorchestra_network.network.id
                              }
                              
                                disk {
                                  sr_id = data.xenorchestra_sr.sr.id
                                  name_label = "VM boot drive"
                                  size = 50212254720
                                }
                              }
                              

                              I'm still getting this error

                              
                              │ Error: jsonrpc2: code 10 message: invalid parameters: {"errors":[{"instancePath":"/VIFs/0/mac","schemaPath":"#/properties/VIFs/items/properties/mac/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"}]}
                              │
                              │   with xenorchestra_vm.rbbmspcs2,
                              │   on vm.tf line 22, in resource "xenorchestra_vm" "rbbmspcs2":
                              │   22: resource "xenorchestra_vm" "rbbmspcs2" {
                              │
                              ╵
                              
                              

                              I am not understanding this. Lin 22 is in the resource section for the VM.

                              1 Reply Last reply Reply Quote 0
                              • G Offline
                                gsrfan01
                                last edited by

                                I'm curious if this is something with Windows, does it work on an Ubuntu VM with cloud-init?

                                R 1 Reply Last reply Reply Quote 0
                                • R Offline
                                  rochemike @gsrfan01
                                  last edited by

                                  @gsrfan01 I don't know what to say. I have just tried to use 2 different TF files I was using to deploy Windows templates in XOA - I was not experiencing any of these errors before.

                                  Now I am, and I am not having a good time of figuring out what is causing this.

                                  Not sure what Windows could have to do with it - I'm running these commands on a RHEL Linux host - the errors occurs almost immediately after the command runs.

                                  Very frustrating.

                                  1 Reply Last reply Reply Quote 0
                                  • G Offline
                                    gsrfan01
                                    last edited by gsrfan01

                                    I meant the template you're using to clone which is Windows.

                                    Is it a Windows Server VM with Cloudbase-Init installed, then converted to a template?

                                    1 Reply Last reply Reply Quote 0
                                    • V Offline
                                      vinh.q.nguyen
                                      last edited by

                                      @rochemike
                                      I had the same issue as you did.

                                      To get around this error.
                                      "│ Error: jsonrpc2: code 10 message: invalid parameters: {"errors":[{"instancePath":"/VIFs/0/mac","schemaPath":"#/properties/VIFs/items/properties/mac/minLength","keyword":"minLength","params":{"limit":1},"message":"must NOT have fewer than 1 characters"}]}
                                      │
                                      │ with xenorchestra_vm.rbbmspcs2,
                                      │ on vm-windows.tf line 19, in resource "xenorchestra_vm""rbbmspcs2":
                                      │ 19: resource "xenorchestra_vm""rbbmspcs2" {"

                                      I modified the tf file to pass a mac_address

                                      network {
                                        network_id = data.xenorchestra_network.cladevops01net1.id
                                        mac_address = be:d0:74:96:5a:66
                                      }
                                      

                                      It would then go and create the VM but once created. I'd log into XO, delete the VIF and readd it to get the randomized MAC address.

                                      Please note that I also tried mac_address = null and mac_address = random which also failed.

                                      Hope it helps.

                                      1 Reply Last reply Reply Quote 0
                                      • olivierlambertO olivierlambert moved this topic from Xen Orchestra on
                                      • First post
                                        Last post