vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 33 forks source link

Cannot cannot unmarshal object into Go value of type bool on Cloud Config #207

Closed jbolthouse closed 1 year ago

jbolthouse commented 1 year ago

Following the guidance in the docs, I attempted to pass a cloud config as a part of initializing a VM and have run aground a Go error:

xenorchestra_cloud_config.bar: Creating...
╷
│ Error: json: cannot unmarshal object into Go value of type bool
│ 
│   with xenorchestra_cloud_config.bar,
│   on main.tf line 32, in resource "xenorchestra_cloud_config" "bar":
│   32: resource "xenorchestra_cloud_config" "bar" {

I have tried various forms of the cloud config and tried the last few releases of this provider and am seeing it happening consistently. Here is my config, with privacy redactions.

I have also tried both loading the cloud config from file and inserting it as you see below. I have also tried only passing hostname as the cloud config, in case any of the parameters were causing the issue.

Terraform validates the config, and I have verified that the connection to our XO is solid.

I dug around in the code for a bit to try to find the offending line, but I can't seem to make the location/stack emit with: export TF_LOG=TRACE && export TF_LOG_PATH=$(pwd)/err.log && terraform apply -- Is there a way to trace back??

Also -- the nmcli config is there only because I failed to notice that a network config could be passed as well, and I hadn't changed that yet. It was a desperate attempt to get everything working in one config.

$ terraform --version
Terraform v1.2.5
on linux_amd64
+ provider registry.terraform.io/terra-farm/xenorchestra v0.23.2
terraform {
  required_providers {
    xenorchestra = {
      source  = "terra-farm/xenorchestra"
      version = "0.23.2"
    }
  }
}

# Configure the XenServer Provider
provider "xenorchestra" {
  # Must be ws or wss
  url      = "REDACTED"             # Or set XOA_URL environment variable
  username = "REDACTED"                 # Or set XOA_USER environment variable
  password = "REDACTED" # Or set XOA_PASSWORD environment variable
  insecure = false                            # Or set XOA_INSECURE environment variable to any value
}

# Content of the terraform files
data "xenorchestra_pool" "pool" {
  name_label = "Dell-Pool"
}

data "xenorchestra_template" "template" {
  name_label = "Rocky 8.5 Cloud Ready_2022-07-21T22:51:17.898Z"
}

data "xenorchestra_network" "net" {
  name_label = "VLAN 2287 Login OpenNMS"
}

resource "xenorchestra_cloud_config" "bar" {
  name = "New Cloud Config Name"
  template = <<EOF
#cloud-config
hostname: swarmhost.dev.login.bz
users:
  - default
  - name: swarm
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    ssh_authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDeY1SWKERJSfMSFbeAJxgtsxxi5dSk182doo6FIkFfvvULapdMXcokTbGFFhzJvYfFmyUQpiI8bnuGalshT9L9Z/xSFy1CkcKle5A4nO6RWE7e5ESDId1GBFKJzUMyxrJHci962VvH17qxMWicKNHTe3OnjYYCNaduWMCnSUpTABxGN7GGSI3EsbHt2ii5KKVuTDwepVV/0ZXpV27f0JNfOfsHY8clGt8Sg+DftReXRvUZDdmnT+f2mOC1q8dLuobL7LoxYDkW/M/WSkrJsyyume7ghhGWCYp3hUtNkE8Ro0ujXGmrr4hrTbVXIF8xgMO9RitxRVoaBXZSNVslmrTY36a3OAs4x2o5uxaGGB6a68WTAIBBgM68JlD1xV1c3YIRa2BNjpzu9K2rkKYKlV5wpcMPZ6YQwz5ZQ9myD+LA561mZ43Edup0YS9CihtwbI015JRvgvJGS48igdRL9Ay4QIQpyW91HXWpQcaD6+sCvtscwf6VTk4XqIwYzVCo0kk=
runcmd:
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.addresses, 10.14.6.4/24]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.gateway, 10.14.6.1]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.dns, 192.195.240.1]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.method, manual]
  - [/usr/bin/nmcli, con, up, "System eth0"]
EOF
}

resource "xenorchestra_vm" "bar" {
  memory_max = 1073733632
  cpus       = 2

  cloud_config     = xenorchestra_cloud_config.bar.template
  name_label       = "Swarm1"
  name_description = "Swarm1 Descr"
  template         = data.xenorchestra_template.template.id
  network {
    network_id = data.xenorchestra_network.net.id
  }
  disk {
    sr_id      = "ea90dea1-99ab-c218-72b4-93abc5abebbe"
    name_label = "Swarm1 HDD"
    size       = 21474836480
  }
  // Override the default create timeout from 5 mins to 20.
  timeouts {
    create = "20m"
  }
}

Here are the errata from the log which may be pertinent:

2022-07-26T02:01:50.113Z [WARN]  Provider "registry.terraform.io/terra-farm/xenorchestra" produced an invalid plan for xenorchestra_vm.bar, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .videoram: planned value cty.NumberIntVal(8) for a non-computed attribute
      - .cpu_weight: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .start_delay: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .auto_poweron: planned value cty.False for a non-computed attribute
      - .wait_for_ip: planned value cty.False for a non-computed attribute
      - .cpu_cap: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .hvm_boot_firmware: planned value cty.StringVal("bios") for a non-computed attribute
      - .core_os: planned value cty.False for a non-computed attribute
      - .exp_nested_hvm: planned value cty.False for a non-computed attribute
      - .vga: planned value cty.StringVal("std") for a non-computed attribute
2022-07-26T02:01:51.344Z [TRACE] readDiff: Read Create change from plan for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.344Z [TRACE] readResourceInstanceState: reading state for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.344Z [TRACE] readResourceInstanceState: no state present for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.344Z [TRACE] readDiff: Read Create change from plan for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.344Z [TRACE] vertex "data.xenorchestra_network.net (expand)": visit complete
2022-07-26T02:01:51.344Z [TRACE] Re-validating config for "xenorchestra_cloud_config.bar"
2022-07-26T02:01:51.344Z [TRACE] GRPCProvider: ValidateResourceConfig
2022-07-26T02:01:51.345Z [TRACE] GRPCProvider: PlanResourceChange
2022-07-26T02:01:51.345Z [TRACE] checkPlannedChange: Verifying that actual change (action Create) matches planned change (action Create)
2022-07-26T02:01:51.345Z [INFO]  Starting apply for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.345Z [DEBUG] xenorchestra_cloud_config.bar: applying the planned Create change
2022-07-26T02:01:51.345Z [TRACE] GRPCProvider: ApplyResourceChange
2022-07-26T02:01:51.354Z [INFO]  provider.terraform-provider-xenorchestra_v0.23.2: 2022/07/26 02:01:51 [TRACE] Made rpc call `cloudConfig.create` with params: map[name:New Cloud COnfig Name template:#cloud-config
hostname: swarmhost.dev.login.bz
users:
  - default
  - name: swarm
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    ssh_authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDeY1SWKERJSfMSFbeAJxgtsxxi5dSk182doo6FIkFfvvULapdMXcokTbGFFhzJvYfFmyUQpiI8bnuGalshT9L9Z/xSFy1CkcKle5A4nO6RWE7e5ESDId1GBFKJzUMyxrJHci962VvH17qxMWicKNHTe3OnjYYCNaduWMCnSUpTABxGN7GGSI3EsbHt2ii5KKVuTDwepVV/0ZXpV27f0JNfOfsHY8clGt8Sg+DftReXRvUZDdmnT+f2mOC1q8dLuobL7LoxYDkW/M/WSkrJsyyume7ghhGWCYp3hUtNkE8Ro0ujXGmrr4hrTbVXIF8xgMO9RitxRVoaBXZSNVslmrTY36a3OAs4x2o5uxaGGB6a68WTAIBBgM68JlD1xV1c3YIRa2BNjpzu9K2rkKYKlV5wpcMPZ6YQwz5ZQ9myD+LA561mZ43Edup0YS9CihtwbI015JRvgvJGS48igdRL9Ay4QIQpyW91HXWpQcaD6+sCvtscwf6VTk4XqIwYzVCo0kk=
runcmd:
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.addresses, 10.14.6.4/24]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.gateway, 10.14.6.1]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.dns, 192.195.240.1]
  - [/usr/bin/nmcli, con, mod, "System eth0", ipv4.method, manual]
  - [/usr/bin/nmcli, con, up, "System eth0"]
] and received false: result with error: json: cannot unmarshal object into Go value of type bool: timestamp=2022-07-26T02:01:51.354Z
2022-07-26T02:01:51.354Z [TRACE] maybeTainted: xenorchestra_cloud_config.bar encountered an error during creation, so it is now marked as tainted
2022-07-26T02:01:51.354Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.354Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.354Z [TRACE] evalApplyProvisioners: xenorchestra_cloud_config.bar is tainted, so skipping provisioning
2022-07-26T02:01:51.354Z [TRACE] maybeTainted: xenorchestra_cloud_config.bar was already tainted, so nothing to do
2022-07-26T02:01:51.354Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.354Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for xenorchestra_cloud_config.bar
2022-07-26T02:01:51.354Z [TRACE] statemgr.Filesystem: not making a backup, because the new snapshot is identical to the old
2022-07-26T02:01:51.354Z [TRACE] statemgr.Filesystem: no state changes since last snapshot
2022-07-26T02:01:51.355Z [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2022-07-26T02:01:51.495Z [ERROR] vertex "xenorchestra_cloud_config.bar" error: json: cannot unmarshal object into Go value of type bool
2022-07-26T02:01:51.495Z [TRACE] vertex "xenorchestra_cloud_config.bar": visit complete, with errors
2022-07-26T02:01:51.495Z [TRACE] dag/walk: upstream of "xenorchestra_vm.bar" errored, so skipping
2022-07-26T02:01:51.495Z [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/terra-farm/xenorchestra\"] (close)" errored, so skipping
2022-07-26T02:01:51.495Z [TRACE] dag/walk: upstream of "root" errored, so skipping
2022-07-26T02:01:51.495Z [TRACE] statemgr.Filesystem: not making a backup, because the new snapshot is identical to the old
2022-07-26T02:01:51.495Z [TRACE] statemgr.Filesystem: no state changes since last snapshot
2022-07-26T02:01:51.495Z [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2022-07-26T02:01:51.499Z [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2022-07-26T02:01:51.499Z [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
2022-07-26T02:01:51.499Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2022-07-26T02:01:51.500Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/terra-farm/xenorchestra/0.23.2/linux_amd64/terraform-provider-xenorchestra_v0.23.2 pid=79259
2022-07-26T02:01:51.500Z [DEBUG] provider: plugin exited
4censord commented 1 year ago

This has already been fixed in #206, but there has not been a release since.

Until that is released, you can

Duplicate of #204

@ddelnano Can we do a release soon?

ddelnano commented 1 year ago

@4censord thanks for linking the previous issue. I'm trying to get a release out today or tomorrow.

jbolthouse commented 1 year ago

Sorry I didn't make the connnection between these. Makes sense now.

On Tue, Jul 26, 2022 at 9:01 AM Dom Del Nano @.***> wrote:

@4censord https://github.com/4censord thanks for linking the previous issue. I'm trying to get a release out today or tomorrow.

— Reply to this email directly, view it on GitHub https://github.com/terra-farm/terraform-provider-xenorchestra/issues/207#issuecomment-1195673701, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKXZAM2FYQMX5PY454KLTVWADUTANCNFSM54WJZNOQ . You are receiving this because you authored the thread.Message ID: @.*** com>

-- John Bolthouse https://www.linkedin.com/in/johnbolthouse https://www.linkedin.com/in/johnbolthouse May all our earnest efforts to accomplish anything find themselves seasoned with salt.

ddelnano commented 1 year ago

This will be fixed in v0.23.3 which will be released within the next hour.