Skip to content

Provider crashes with nil pointer errors when reading VMs with incomplete configurations #1452

@anton-ane

Description

@anton-ane

Summary

The Terraform Proxmox provider (v3.0.2-rc05) crashes with panic errors (interface conversion: interface {} is nil, not string) when attempting to read VMs that have incomplete or partially configured components. This can occur with IDE disk devices, CPU configurations, or other VM attributes that are in an incomplete state (e.g., added via terraform with "automatic_reboot = false" argument, or added via Proxmox Web UI without VM reboot).

Provider Version

terraform-provider-proxmox v3.0.2-rc05

Terraform Version

Terraform v1.13.4

Affected Resource(s)

  • proxmox_vm_qemu

Terraform Configuration

resource "proxmox_vm_qemu" "ftp3" {
  name         = "ftp3"
  target_nodes = ["proxmox4"]
  clone        = "alma-clean-linux-template"
  full_clone   = true

  define_connection_info = true
  onboot                 = true
  agent                  = 1
  qemu_os                = "l26"
  automatic_reboot       = false
  automatic_reboot_severity = "warning"
  scsihw                 = "virtio-scsi-single"
  tags                   = "terraform"

  memory  = 4096
  balloon = 0

  cpu {
    cores   = 2
    sockets = 2
    type    = "x86-64-v2-AES"
    numa    = false
  }

  disk {
    slot    = "scsi0"
    type    = "disk"
    storage = "HA-pool"
    size    = "50G"
  }

  network {
    id     = 0
    model  = "virtio"
    bridge = "vmbr0"
  }

  ipconfig0 = "ip=dhcp"
}

Steps to Reproduce

Example: Incomplete IDE Disk Device

  1. Create a VM using Terraform with terraform plan and terraform apply - succeeds
  2. Add a DVD/CD-ROM image to the VM via Proxmox Web UI:
    • Go to VM Hardware settings
    • Add DVD/CD-ROM device at Bus/Device IDE/2
    • Select an ISO image
    • Important: Do NOT reboot the VM (device shows as yellow - not fully implemented)
  3. Run terraform plan -target proxmox_vm_qemu.ftp3 again
  4. Provider crashes with panic error in disksIde() function

Note: Similar errors can occur in other scenarios when VM configurations are incomplete:

  • CPU configuration parsing - crashes in GetCPU()
  • Other VM attributes in incomplete states - crashes in mapToStruct()

Expected Behavior

Terraform should be able to read the VM state even when VM components are in an incomplete or partially configured state. The provider should handle nil values and incomplete configurations gracefully.

Actual Behavior

The provider crashes with a panic error when trying to parse VM configurations that contain nil values:

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

The crash occurs in various functions depending on which component has nil values:

  • disksIde() when IDE disk devices are incomplete
  • GetCPU() when CPU configuration is incomplete
  • mapToStruct() when other VM attributes are incomplete

Error Output

proxmox_vm_qemu.ftp3: Refreshing state... [id=proxmox5/qemu/145]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Request cancelled
│ 
│   with proxmox_vm_qemu.ftp3,
│   on ftp3.tf line 1, in resource "proxmox_vm_qemu" "ftp3":
│    1: resource "proxmox_vm_qemu" "ftp3" {
│ 
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-proxmox_v3.0.2-rc05 plugin:

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

goroutine 24 [running]:
github.com/Telmate/proxmox-api-go/proxmox.(*rawConfigQemu).disksIde(0xc000f839d8, 0xc000efe184)
	github.com/Telmate/[email protected]/proxmox/config__qemu__disk__ide.go:108 +0x28e
github.com/Telmate/proxmox-api-go/proxmox.(*rawConfigQemu).GetDisks(0xc000f839d8)
	github.com/Telmate/[email protected]/proxmox/config__qemu__disk.go:1075 +0x4a
github.com/Telmate/proxmox-api-go/proxmox.(*rawConfigQemu).get(0xc000f839d8, 0xc000bc0d20)
	github.com/Telmate/[email protected]/proxmox/config__qemu.go:1148 +0x445
github.com/Telmate/proxmox-api-go/proxmox.(*rawConfigQemu).Get(0xc00028d710?, 0xf26a49?)
	github.com/Telmate/[email protected]/proxmox/config__qemu.go:1123 +0x13
github.com/Telmate/terraform-provider-proxmox/v2/proxmox.resourceVmQemuRead({0x108b6d8, 0xc0000faee0}, 0xc00028d710, {0xd6dea0?, 0xc000a2d2c0})
	github.com/Telmate/terraform-provider-proxmox/v2/proxmox/resource_vm_qemu.go:997 +0x77c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000540a00, {0x108b630, 0xc000dcd6e0}, 0xc00028d710, {0xd6dea0, 0xc000a2d2c0})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:866 +0x119
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000540a00, {0x108b630, 0xc000dcd6e0}, 0xc000e36270, {0xd6dea0, 0xc000a2d2c0})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1162 +0x52a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00037c000, {0x108b630?, 0xc000dcd620?}, 0xc0005de7d0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:908 +0xb6d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0002800a0, {0x108b630?, 0xc000ccae0?}, 0xc0000fa9a0)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:859 +0x2f3
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xefdb20, 0xc0002800a0}, {0x108b630, 0xc000ccae0}, 0xc0001a5c80, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:651 +0x1a9
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000262400, {0x108b630, 0xc000dcca50}, 0xc00028aba0, 0xc000982630, 0x1729fb8, 0x0)
	google.golang.org/[email protected]/server.go:1405 +0x1036
google.golang.org/grpc.(*Server).handleStream(0xc000262400, {0x108c010, 0xc0007a01a0}, 0xc00028aba0)
	google.golang.org/[email protected]/server.go:1815 +0xb88
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1035 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 40
	google.golang.org/[email protected]/server.go:1046 +0x11d

Error: The terraform-provider-proxmox_v3.0.2-rc05 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.

Root Cause Analysis

The panic occurs when the provider attempts to convert nil interface values to strings without proper nil checking. This is a systemic issue affecting multiple parts of the codebase:

  1. IDE Disk Devices (proxmox/config__qemu__disk__ide.go:108 in disksIde()):

    • When IDE devices are added but not fully active
    • The Proxmox API returns incomplete or nil values for certain IDE device properties
    • The provider attempts to convert these nil values to strings without checking
  2. CPU Configuration (proxmox/config__qemu__cpu.go:629 in GetCPU()):

    • When CPU configuration is not fully active
  3. General Configuration (proxmox/config__qemu.go:376 in mapToStruct()):

    • When any VM attribute is not fully active

The common pattern is that the provider does not handle nil values gracefully when parsing VM configuration from the Proxmox API. This is particularly problematic when:

  • Components are added via terraform with "automatic_reboot = false" argument
  • Components are added manually via Proxmox Web UI
  • Components are in an incomplete/transitional state (yellow status in Proxmox)

Workaround

Temporary workarounds (depending on the affected component):

  • Reboot the VM after adding the device, or remove the device before running terraform plan
  • Remove manually added components that are in incomplete states

However, these workarounds are not ideal as they require manual intervention and defeat the purpose of infrastructure-as-code.

Additional Context

  • This issue occurs when VM components are added or modified without VM reboot (shutdown & start) to implement the changes
  • The issue does not occur if all components are fully active and properly configured
  • The problem manifests when components are in an incomplete/transitional state (yellow status in Proxmox)
  • This affects multiple areas: IDE disks, CPU config and potentially other VM attributes
  • This is a regression/breaking issue that prevents normal Terraform operations

Related Issues

This appears to be related to similar nil pointer issues reported in:

  • CPU configuration parsing (when CPU config is nil)
Stack trace from the terraform-provider-proxmox_v3.0.2-rc05 plugin:

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

goroutine 9 [running]:
github.com/Telmate/proxmox-api-go/proxmox.(*rawConfigQemu).GetCPU(0xc00100a100)
	github.com/Telmate/[email protected]/proxmox/config__qemu__cpu.go:629 +0x716
...
  • Other cases (when other config is nil)
Stack trace from the terraform-provider-proxmox_v3.0.2-rc05 plugin:

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

goroutine 56 [running]:
github.com/Telmate/proxmox-api-go/proxmox.(*ConfigQemu).mapToStruct(0xc00025a1e0, 0xc000970640?, 0xc00164d410)
	github.com/Telmate/[email protected]/proxmox/config__qemu.go:376 +0x1485
...

The common pattern is that the provider does not handle nil values gracefully when parsing VM configuration from the Proxmox API.

Environment

  • Proxmox Version: PVE 8.4.12
  • Terraform Version: 1.13.4
  • Provider Version: 3.0.2-rc05
  • Operating System: AlmaLinux release 9.6 (Sage Margay)

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/confirmedIssue has been reviewed and confirmed to be present or accepted to be implementedissue/criticalThis issue should be fixed ASAP. If it is a PR, the PR should be merged ASAPresource/qemuIssue or PR related to Qemu resourcetype/bugtype/upstreamThis is an issue in one of our dependencies and should be reported there

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions