Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Planning throws error about unmarshalling number into struct field of type string #98

Closed
magikid opened this issue Jul 16, 2021 · 4 comments · May be fixed by #99 or #105
Closed

[BUG] Planning throws error about unmarshalling number into struct field of type string #98

magikid opened this issue Jul 16, 2021 · 4 comments · May be fixed by #99 or #105

Comments

@magikid
Copy link

magikid commented Jul 16, 2021

Describe the bug
When running terraform plan, I get this error:

│ Error: Failed to decode HTTP GET response (path: nodes/planetexpressship/qemu/105/status/current) - Reason: json: cannot unmarshal number into Go struct field VirtualEnvironmentVMGetStatusResponseData.data.pid of type string

To Reproduce
Apply this terraform file and then run terraform plan

resource "proxmox_virtual_environment_pool" "utility" {
  comment = "Managed by Terraform"
  pool_id = "utility"
}

resource "proxmox_virtual_environment_vm" "nomad_leaders" {
  count       = 3
  name        = "nomad-leader-${count.index}"
  node_name   = "planetexpressship"
  pool_id     = "${proxmox_virtual_environment_pool.utility.id}"

  agent {
    enabled   = true
  }

  clone {
    vm_id = "${var.leader_image_id}" # Use any image id
  }

  network_device {
    model     = "virtio"
    bridge    = "vmbr1"
  }
}

Expected behavior
I expected terraform plan to show that no infrastructure changes were needed.

Screenshots
If applicable, add screenshots to help explain your problem.

😎  λ ~/ansible/proxmox-terraform/terraform/ main* terraform plan
proxmox_virtual_environment_pool.building: Refreshing state... [id=building]
proxmox_virtual_environment_pool.utility: Refreshing state... [id=utility]
proxmox_virtual_environment_pool.smart-home: Refreshing state... [id=smart-home]
proxmox_virtual_environment_pool.media: Refreshing state... [id=media]
proxmox_virtual_environment_vm.nomad-leader[1]: Refreshing state... [id=107]
proxmox_virtual_environment_vm.nomad-leader[0]: Refreshing state... [id=106]
proxmox_virtual_environment_vm.nomad-leader[2]: Refreshing state... [id=105]
╷
│ Error: Failed to decode HTTP GET response (path: nodes/planetexpressship/qemu/105/status/current) - Reason: json: cannot unmarshal number into Go struct field VirtualEnvironmentVMGetStatusResponseData.data.pid of type string
│ 
│ 
╵
╷
│ Error: Failed to decode HTTP GET response (path: nodes/planetexpressship/qemu/106/status/current) - Reason: json: cannot unmarshal number into Go struct field VirtualEnvironmentVMGetStatusResponseData.data.vmid of type string
│ 
│ 
╵
╷
│ Error: Failed to decode HTTP GET response (path: nodes/planetexpressship/qemu/107/status/current) - Reason: json: cannot unmarshal number into Go struct field VirtualEnvironmentVMGetStatusResponseData.data.vmid of type string
│ 
│ 
╵

Additional context
Add any other context about the problem here.

@Alfablos
Copy link

I have the same issue but with storage:

Error: Failed to decode HTTP GET response (path: nodes/MYNODE/storage/MYSTORAGE/content) - Reason: json: cannot unmarshal string into Go struct field VirtualEnvironmentDatastoreFileListResponseData.data.size of type int

The same happens with VirtualEnvironmentDatastoreFileListResponseData.data.used

As a matter of fact the api responds with the following data:

{
    "data": [
        {
            "ctime": 1631894713,
            "parent": null,
            "used": "710836736",                      # String!
            "format": "qcow2",
            "size": "2361393152",                     # String!
            "vmid": 100,                                    # Int
            "content": "images",
            "volid": "threetb:100/base-100-disk-0.qcow2"
        }
    ]
}

Changing from the original proxmox/virtual_environment_datastores_types.go

// VirtualEnvironmentDatastoreFileListResponseData contains the data from a datastore content list response.
type VirtualEnvironmentDatastoreFileListResponseData struct {
	ContentType    string  `json:"content"`
	FileFormat     string  `json:"format"`
	FileSize       int     `json:"size"`
	ParentVolumeID *string `json:"parent,omitempty"`
	SpaceUsed      *int    `json:"used,omitempty"`
	VMID           *int    `json:"vmid,omitempty"`
	VolumeID       string  `json:"volid"`
}

to something apparently more consistent

// VirtualEnvironmentDatastoreFileListResponseData contains the data from a datastore content list response.
type VirtualEnvironmentDatastoreFileListResponseData struct {
	ContentType    string  `json:"content"`
	FileFormat     string  `json:"format"`
	FileSize       string     `json:"size"`
	ParentVolumeID *string `json:"parent,omitempty"`
	SpaceUsed      *string    `json:"used,omitempty"`
	VMID           *int    `json:"vmid,omitempty"`
	VolumeID       string  `json:"volid"`
}

brings no benefits.
Fair enough though, I think, since just changing the struct won't avoid the need to adjust the rest of the code, which won't be able to work with these types (E.G. when comparing old and new sizes using a mathematical operator like '>')

Lastly, when I change the code as in the last snippet I get:
Error: Failed to decode HTTP GET response (path: nodes/virt/storage/threetb/content) - Reason: json: cannot unmarshal number into Go struct field VirtualEnvironmentDatastoreFileListResponseData.data.size of type string

I think something interesting comes from proxmoxtf/data_source_virtual_environment_datastores.go but I really don't know how the terraform SDK relates to this code.

@magikid Unfortunately your implementation doesn't seem to work in my case either.
I'm new to go and programming so I'm certaintly not able to troubleshoot this alone, but I'm more than willing to help!

@bpg
Copy link

bpg commented Oct 26, 2021

just fyi, I merged this fix above and made few other improvements in the fork and published it to the terraform registry, if anyone interested: https://github.com/bpg/terraform-provider-proxmox

@me-nilix
Copy link

No, nothing has been fixed, I compiled from sources last night.
lxc

2021-10-28T02:51:49.267-0400 [DEBUG] provider.terraform-provider-proxmox_v0.4.6: 2021/10/28 02:51:49 [DEBUG] Performing HTTP GET request (path: nodes/pxe-server/lxc/101/status/current)
2021-10-28T02:51:49.274-0400 [DEBUG] provider.terraform-provider-proxmox_v0.4.6: 2021/10/28 02:51:49 [DEBUG] WARNING: Failed to decode HTTP GET response (path: nodes/pxe-server/lxc/101/status/current) - Reason: json: cannot unmarshal string into Go struct field VirtualEnvironmentContainerGetStatusResponseData.data.vmid of type int

When running terraform apply

@magikid
Copy link
Author

magikid commented Jan 24, 2022

@bpg Thank you! I can confirm that fixes my issue.

@magikid magikid closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants