Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.13k stars 515 forks source link

panic: interface conversion: interface {} is string, not float64 in 3.0.1-rc4 provider. #1114

Open gillespiem opened 5 days ago

gillespiem commented 5 days ago

When attempting to create a linux container using terraform-provider-proxmox version 3.0.1-rc4, the plugin crashes as follows:

Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-proxmox_v3.0.1-rc4 plugin:

panic: interface conversion: interface {} is string, not float64

goroutine 38 [running]:
github.com/Telmate/proxmox-api-go/proxmox.NewConfigLxcFromApi(0xc000802ff0, 0xc000802ff0?)
        github.com/Telmate/proxmox-api-go@v0.0.0-20240827160542-0d787afdba05/proxmox/config_lxc.go:160 +0x1e85
github.com/Telmate/terraform-provider-proxmox/v2/proxmox._resourceLxcRead(0xc0005ce780, {0xbde960?, 0xc00007e640})
        github.com/Telmate/terraform-provider-proxmox/v2/proxmox/resource_lxc.go:781 +0x20e
github.com/Telmate/terraform-provider-proxmox/v2/proxmox.resourceLxcRead(0x0?, {0xbde960?, 0xc00007e640?})
        github.com/Telmate/terraform-provider-proxmox/v2/proxmox/resource_lxc.go:763 +0x1d
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xe753d8?, {0xe753d8?, 0xc000679b90?}, 0xd?, {0xbde960?, 0xc00007e640?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:811 +0x163
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00059eee0, {0xe753d8, 0xc000679b90}, 0xc0006b41a0, {0xbde960, 0xc00007e640})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:1117 +0x552
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00033c2d0, {0xe753d8?, 0xc000679aa0?}, 0xc000647440)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:708 +0x6ca
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc000242aa0, {0xe753d8?, 0xc000679050?}, 0xc000445260)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:783 +0x309
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xd109e0?, 0xc000242aa0}, {0xe753d8, 0xc000679050}, 0xc00027ff80, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:482 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000e3800, {0xe753d8, 0xc000678f90}, {0xe79498, 0xc00023e480}, 0xc000704000, 0xc0005bc090, 0x13d3da8, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc0000e3800, {0xe79498, 0xc00023e480}, 0xc000704000)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 51
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x135

Error: The terraform-provider-proxmox_v3.0.1-rc4 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

While there is another recently filed (issue #1113), that issue is filed in version 2 of the provider and it is noted that one should use version 3. As noted, this is also present there.

terraform providers

Providers required by configuration:
.
└── provider[registry.terraform.io/telmate/proxmox] 3.0.1-rc4

Providers required by state:

    provider[registry.terraform.io/telmate/proxmox]

Proxmox version: 8.2.2

Example that can be used to replicate:

terraform {
  required_providers {
    proxmox = {
      source = "Telmate/proxmox"
      version = "3.0.1-rc4"
    }
  }
}

provider "proxmox" {

 pm_api_url   = "https://my-node:8006/api2/json"
 pm_api_token_id = "terraform@pam!terraform"
 pm_api_token_secret  = "<<OMMITTED>>
 pm_tls_insecure = true

}

resource "proxmox_lxc" "lxc-test" {
    features {
        nesting = true
    }
    hostname = "terraform-new-container"
    network {
        name = "eth0"
        bridge = "vmbr0"
        ip = "dhcp"
        ip6 = "dhcp"
    }
    ostemplate = "local:vztmpl/devuan-4.0-standard_4.0_amd64.tar.gz"
    password = "rootroot"
    target_node = "pve"
    unprivileged = true
}
gillespiem commented 19 hours ago

I placed HTTP-Toolkit as a proxy between my Terraform CLI and Proxmox and performed a Terraform apply. In doing so, I found the following APIs being called:

https://virtual0.myproxmox.com:8006/api2/json/access/users?full=1 https://virtual0.myproxmox.com:8006/api2/json/access/permissions?userid=terraform@pam&path=/ https://virtual0.myproxmox.com:8006/api2/json/cluster/resources?type=vm https://virtual0.myproxmox.comt:8006/api2/json/nodes/virtual0/qemu/105/config

It's after the API call to /api2/json/nodes/virtual0/qemu/105/config that the previously noted crashing occurs.

Looking at the json payload from the /api2/json/cluster/resources?type=vm API call, I do see 105 as listed:


    {
      "maxcpu": 4,
      "type": "qemu",
      "template": 0,
      "id": "qemu/105",
      "name": "proxmox-test",
      "netout": 0,
      "disk": 0,
      "maxdisk": 34359738368,
      "vmid": 105,
      "mem": 0,
      "uptime": 0,
      "diskwrite": 0,
      "diskread": 0,
      "netin": 0,
      "maxmem": 17179869184,
      "node": "virtual0",
      "cpu": 0,
      "status": "stopped"
    },

The JSON for the 105 vm is as follows:

{
  "data": {
    "ide2": "local:iso/proxmox-ve_8.2-2.iso,media=cdrom,size=1364160K",
    "net0": "virtio=BC:24:11:17:E2:0C,bridge=vmbr0,firewall=1",
    "meta": "creation-qemu=8.1.5,ctime=1725580626",
    "cpu": "x86-64-v2-AES",
    "smbios1": "uuid=9bb63453-e80a-4ab3-ab90-537a1a977a8e",
    "boot": "order=scsi0;ide2;net0",
    "vmgenid": "7351306b-21eb-43ac-903f-cab45550b5a6",
    "name": "proxmox-test",
    "digest": "aea0ebb206b1ceb4ec3e26694a5e8e330f28cef7",
    "scsi0": "local-lvm:vm-105-disk-0,iothread=1,size=32G",
    "numa": 0,
    "memory": "16384",
    "sockets": 2,
    "ostype": "l26",
    "cores": 2,
    "scsihw": "virtio-scsi-single"
  }
}

Because that is an unused VM, I decided to delete it and test. I am now able to create containers via Terraform without issue (I've created 2 - the first one numbered itself as 105, the second as 127.

I'm not clear what about 105 caused the issue, but the problem appears to now be resolved.