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

    XO and terraform

    Scheduled Pinned Locked Moved Infrastructure as Code
    6 Posts 3 Posters 412 Views 3 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.
    • W Offline
      wezke
      last edited by olivierlambert

      hi guys

      im rather new to XCP and Terraform.

      I am an adult student in system and network engineering (last year) and for my project i have chosen to deploy VMs with terraform. configuring with most likely ansible.

      So far i am able to deploy a VM however at first run of my ''playbook'' it creates the VM and no disk is being created. second run the disk is created and attached but in a diconnected state.

      then i need to shut down the VM in XO and run my terraform template once again, the VM is being powered on and the disk is connected.

      im not sure what causes this behaviour.

      here is my current template.

      here is my current template.

      terraform {
        required_providers {
          xenorchestra = {
            source  = "terra-farm/xenorchestra"
            version = "~> 0.26.0"
          }
        }
      }
      
      provider "xenorchestra" {
        url      = "wss://"my_xo_ip"
        username = "myusername"
        password = "Mypassword"
        insecure = true
      }
      
      # Fetch the template
      data "xenorchestra_template" "vm_template" {
        name_label = "Terraform_Template_Win_Core"
      }
      
      # Fetch the network
      data "xenorchestra_network" "network" {
        name_label = "eth0"
      }
      
      # Fetch the storage repository
      data "xenorchestra_sr" "sr" {
        name_label = "Local storage"
      }
      
      # Create the VM with explicit dependency on the storage repository
      resource "xenorchestra_vm" "vm1" {
        name_label = "terraform_VM"
        template   = data.xenorchestra_template.vm_template.id
        cpus       = 2
        memory_max = 4294967296
      
        # Network configuration
        network {
          network_id = data.xenorchestra_network.network.id
        }
      
        # Disk configuration with explicit dependency on storage repository
        disk {
          sr_id      = data.xenorchestra_sr.sr.id
          size       = 10737418240
          name_label = "VM root volume"
        }
      
        # CD-ROM configuration
        cdrom {
          id = "09ab237e-9a35-4d88-b787-24c1b6fa7779"
        }
      
        # Automatically power on the VM
        power_state = "Running"
      
        # Ensure the VM depends on the successful creation of the storage repository
        depends_on = [data.xenorchestra_sr.sr]
      }
      

      its also suboptimal as i then would need to run the windows ISO from the XO console..

      any tips would be greatly appreciated.

      nathanael-hN 1 Reply Last reply Reply Quote 0
      • nathanael-hN Offline
        nathanael-h Vates 🪐 DevOps Team @wezke
        last edited by

        @wezke Hello, can you switch to this latest version of the provider, ensure that your configuration is still valid or fix what would be needed, and report how it behaves?

        https://registry.terraform.io/providers/vatesfr/xenorchestra/latest

        W 1 Reply Last reply Reply Quote 0
        • W Offline
          wezke @nathanael-h
          last edited by nathanael-h

          @nathanael-h

          changed block provider to the latest version

          terraform {
            required_providers {
              xenorchestra = {
                source  = "vatesfr/xenorchestra"
                version = "0.29.0"
              }
            }
          }
          

          acts just the same way i must say.

          CyrilleC 1 Reply Last reply Reply Quote 0
          • CyrilleC Offline
            Cyrille Vates 🪐 DevOps Team @wezke
            last edited by

            @wezke Hi, I have no problem running your terraform plan, maybe there is a problem with the template you are using? How did you create it?

            There is no warning during the tf execution?

            W 1 Reply Last reply Reply Quote 0
            • W Offline
              wezke @Cyrille
              last edited by wezke

              @Cyrille

              ive made the template from running an Windows 2022 from my iso storage untill initial process was installed, shutdown the vm and created a template.

              Edit: you are correct, using a builtin template has no issue's.
              going to solve that problem first 🙂

              thank you for the support

              CyrilleC 1 Reply Last reply Reply Quote 0
              • CyrilleC Offline
                Cyrille Vates 🪐 DevOps Team @wezke
                last edited by

                @wezke you are welcome. let us know if you find the explanation for the problem with the template 🙂

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post