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

    Automating VM creation via Terraform

    Scheduled Pinned Locked Moved Xen Orchestra
    7 Posts 4 Posters 3.0k Views 1 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.
    • E Offline
      eperez539
      last edited by

      I'm starting to use Terraform to provision new vms and followed the configuration from the xenorchestra provider for Terraform:
      https://terra-farm.github.io/provider-xenorchestra/index.html
      but running into following issue:

      Error: websocket: bad handshake
      
        on main.tf line 7, in data "xenorchestra_template" "template":
         7: data "xenorchestra_template" "template" {
      
      

      Is there anything I need to enable on XenOrchestra so the websocket connection works?

      1 Reply Last reply Reply Quote 0
      • olivierlambertO Offline
        olivierlambert Vates 🪐 Co-Founder CEO
        last edited by

        We'll take a look after our monthly release! ping @julien-f

        1 Reply Last reply Reply Quote 0
        • julien-fJ Offline
          julien-f Vates 🪐 Co-Founder XO Team
          last edited by

          @eperez539 Hi, the WebSocket API of Xen Orchestrea, is always enabled, please check the URL and, if it still does not work, ask help on Terraform 🙂

          E 1 Reply Last reply Reply Quote 0
          • E Offline
            eperez539 @julien-f
            last edited by

            @julien-f Yes, I had the xcp-ng host ip instead of XO ip. After changing that, getting different error now:

            Error: jsonrpc2: code -32000 message: unknown error from the peer
            
              on main.tf line 53, in resource "xenorchestra_vm" "base":
              53: resource "xenorchestra_vm" "base" {
            
            

            Here is what my tf file looks like:

            provider "xenorchestra" {
              url = "ws://XO_IP_HERE"
              username = "USERNAME"
              password = "PASSWORD"
            }
            
            data "xenorchestra_template" "template" {
              name_label = "Ubuntu Bionic Beaver 18.04"
            }
            
            data "xenorchestra_pif" "pif" {
              device = "eth0"
              vlan = -1
            }
            
            resource "xenorchestra_cloud_config" "base" {
              name = "cloudconfig"
              template = <<EOF
            #cloud-init
            tiemzone: America/New_York
            hostname: terraformtest
            package_update: true
            package_upgrade: true
            users:
              - name: test
                gecos: Test User
                groups: sudo
                passwd: test
                sudo: ['ALL=(ALL) NOPASSWD:ALL']
            
            network:
              version: 2
              ethernets:
                eno1:
                  dhcp4: no
                  addresses: [192.168.0.40/24]
                  gateway4: 192.168.0.1
                  nameservers:
                     addresses: [192.168.0.1]
            
            runcmd:
             - [ ls, -l, / ]
             - [ sh, -xc, "echo $(date) ': hello world!'" ]
             - [ sh, -c, echo "=========hello world'=========" ]
             - ls -l /root
            EOF
            }
            
            resource "xenorchestra_vm" "base" {
                memory_max = 1073733632
                cpus  = 2
                cloud_config = "${xenorchestra_cloud_config.base.template}"
                name_label = "TerraformVM"
                name_description = "Created by Terraform Script"
                template = "${data.xenorchestra_template.template.id}"
                network {
            	    network_id = "${data.xenorchestra_pif.pif.network}"
                }
            
                disk {
                  sr_id = "388ccc18-9b21-22cc-dfa9-db4c8c3a4959"
                  name_label = "Terraform_disk_imavo"
                  size = 32212254720
                }
            }
            
            

            Do you happen to see what I'm doing wrong here? Thanks

            newknowledgeN 1 Reply Last reply Reply Quote 0
            • julien-fJ Offline
              julien-f Vates 🪐 Co-Founder XO Team
              last edited by

              I'm not familiar with Terraform, but I can tell you that you can get more info about an unknown error from the peer error in XO on the Settings > Logs page.

              1 Reply Last reply Reply Quote 0
              • newknowledgeN Offline
                newknowledge @eperez539
                last edited by newknowledge

                @eperez539
                The line #cloud-init should be replaced with #cloud-config. The official xen terraform template is wrong

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  eperez539 @newknowledge
                  last edited by

                  @newknowledge Thanks, I'll try it out later.

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post