Automating VM creation via Terraform
-
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?
-
We'll take a look after our monthly release! ping @julien-f
-
@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
-
@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
-
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. -
@eperez539
The line #cloud-init should be replaced with #cloud-config. The official xen terraform template is wrong -
@newknowledge Thanks, I'll try it out later.