Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.1k stars 509 forks source link

HostPCI Invalid address set. #1029

Open Stormfox2 opened 3 months ago

Stormfox2 commented 3 months ago

Hey, I'm trying to add two hostpci devices to one of my vms. Everything worked until I try to run another terraform plan.

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

╷
│ Error: Invalid address to set: []string{"hostpci", "0", "id"}
│ 
│   with proxmox_vm_qemu.nas_server[0],
│   on nas.tf line 1, in resource "proxmox_vm_qemu" "nas_server":
│    1: resource "proxmox_vm_qemu" "nas_server" {
│ 
╵

image

resource "proxmox_vm_qemu" "nas_server" {
  # Set 0 to purge 
  count = 1
  name = "nas0${count.index+1}.ketarion.local"

  # Vars
  target_node = var.proxmox_host_01

  # Basic settings
  cores = 2
  sockets = 1
  cpu = "host"
  memory = 8192
  onboot = true
  startup = "order=2"

  # Startup info
  agent = 1

  # CLONE
  # clone = var.template_name 

  disks {
    # ISO 
    ide {
      ide2 {
        cdrom {
          iso = var.nfs_iso
        }
      }
    }

    # Disks
    scsi {
        scsi0 {
            disk {
                size = "100G"
                storage = "local-zfs"
            }
        }
        scsi1 {
            disk {
                size = "80G"
                storage = "local-zfs"
            }
        }
        scsi2 {
            disk {
                size = "80G"
                storage = "local-zfs"
            }
        }
        scsi3 {
            disk {
                size = "80G"
                storage = "local-zfs"
            }
        }
        scsi4 {
            disk {
                size = "80G"
                storage = "local-zfs"
            }
        }
    }
  }

  hostpci {
    host = "0000:2c:00"
  }

  hostpci {
    host = "0000:2d:00"
  }

  network {
    model = "virtio"
    firewall  = false
    link_down = false
    bridge = "vmbr100"
    tag = "30"
  }

  # Defaults, dont change if you dont know what you do
  scsihw = "virtio-scsi-pci"
  # bootdisk = "scsi0"
  # Cloud init
  # os_type = "cloud-init"
  # Standalone 
  os_type = "Linux 6.x - 2.6 Kernel"
  lifecycle {
    ignore_changes = [
      network,
    ]  
  }  

  # ipconfig0 = "ip=10.0.100.${count.index+1}/16,gw=10.0.100.254"

  # Ignore IP for non Template servers
  skip_ipv6 = true

  # sshkeys = <<EOF
  # ${var.ssh_key}
  # EOF
}

From the logs:

Sat, 01 Jun 2024 00:06:16 +0200 DBG github.com/Telmate/terraform-provider-proxmox/v2/proxmox/resource_vm_qemu.go:1530 > Hostpci Block Processed 'map[0:map[:<nil> id:0 rombar:0]]' loggerName=resource_vm_read vmid=102
Aksogen commented 3 months ago

Yeah, I observe the same behavior when I try to create a virtual machine with pci device: "3.0.1-rc2"

variable:

variable "vm_pci_devices" {
  type = list(object({
    id     = string
    rombar = number
    pcie   = number
  }))
  default   = [] 
}

resource:

dynamic hostpci {
      for_each = var.vm_pci_devices
      content {
          host   = hostpci.value.id
          rombar = hostpci.value.rombar
          pcie   = hostpci.value.pcie
      }
}

module with variable:

  vm_pci_devices = [
      { id = "0000:00:02", rombar = 1, pcie = 0 }
  ]

Error:

 Error: Invalid address to set: []string{"hostpci", "0", "id"}
│
│   with module.altair.proxmox_vm_qemu.proxmox_vm[0],
│   on modules\proxmox-vm-qemu\main.tf line 1, in resource "proxmox_vm_qemu" "proxmox_vm":
│    1: resource "proxmox_vm_qemu" "proxmox_vm" {
Aksogen commented 3 months ago

@mleone87 , Hi. Any comments?

lucian-tx commented 3 weeks ago

Hey @Aksogen @Stormfox2 maybe this PR will help with your issue? https://github.com/Telmate/terraform-provider-proxmox/pull/1070

m-da-costa commented 2 weeks ago

Actually did not fixed for me :O I'm using the master branch binary Proxmox Version: 8.2.3 Resource:

resource "proxmox_vm_qemu" "k0s-gpu-worker" {
  name = "k0s-gpu-worker"
  target_node = "cloud"
  desc        = "GPU worker k0s"
  onboot      = true
  clone = "d12-normal-gpu"
  agent   = 0
  machine = "q35"
  hostpci {
    host   = "p40"
    pcie   = 0
    rombar = 1
  }
  os_type  = "cloud-init"
  numa     = true
  cpu      = "host"
  scsihw   = "virtio-scsi-single"
  bootdisk = "scsi0"
  disks {
    ide {
      ide3 {
        cloudinit {
          storage = "local-lvm"
        }
      }
    }
    scsi {
      scsi0 {
        disk {
          storage = "local-lvm"
          size    = 100
        }
      }
    }
  }
  network {
    model    = "virtio"
    bridge   = "vmbr0"
    firewall = false
  }
}

Error:

{
"data":null,
"errors":{"hostpci0":"invalid format - format error\nhostpci0.host: value does not match the regex pattern\n"}} (params: map[agent:0 balloon:0 bios:seabios cicustom:  ciupgrade:0  cores:1 cpu:host delete:ide2,searchdomain,shares description:GPU worker k0s hostpci0:pcie=0,host=p40,rombar=1 hotplug:network,disk,usb ide3:local-lvm:cloudinit,format=raw kvm:true machine:q35 memory:512 name:k0s-gpu-worker  ,bridge=vmbr0 numa:1 onboot:true protection:false scsi0:local-lvm:vm-103-disk-0,replicate=0 scsihw:virtio-scsi-single sockets:1 tablet:true vmid:103])

After running terraform apply again:

proxmox_vm_qemu.k0s-gpu-worker: Refreshing state... [id=cloud/qemu/103]
╷
│ Error: unable to set hostpci: Invalid address to set: []string{"hostpci", "0", "mapping"}
│ 
│   with proxmox_vm_qemu.k0s-gpu-worker,
│   on main.tf line 190, in resource "proxmox_vm_qemu" "k0s-gpu-worker":
│  190: resource "proxmox_vm_qemu" "k0s-gpu-worker" {
│ 
╵

but ~~~ When I use the following config: image With the following commented:

  # machine     = "q35"
  # hostpci {
  #   host   = "p40"
  #   pcie   = 0
  #   rombar = 1
  # }

It stills return the error:

proxmox_vm_qemu.k0s-gpu-worker: Refreshing state... [id=cloud/qemu/103]
╷
│ Error: unable to set hostpci: Invalid address to set: []string{"hostpci", "0", "mapping"}
│ 
│   with proxmox_vm_qemu.k0s-gpu-worker,
│   on main.tf line 190, in resource "proxmox_vm_qemu" "k0s-gpu-worker":
│  190: resource "proxmox_vm_qemu" "k0s-gpu-worker" {
│ 
╵

But the VM starts, and: image

I believe there's something wrong with the regex and or the validation in the CI routine. Or something Idk. I Hope it helped.

lucian-tx commented 2 weeks ago

Hey @m-da-costa, looks like you're encountering two different problems that are unrelated to OP's id error.

hostpci0.host: value does not match the regex pattern

I guess you'll have to check what's up with the host that (as the error points out) does not meet the regex rule. Here I have no clue.

Invalid address to set: []string{"hostpci", "0", "mapping"}

I believe that mapping is simply not supported at this time by this plugin. I have it on my roadmap somewhere down the line, if nobody else adds this feature in the meantime, I'll ping you when the PR is open, with support for mapping.

Tinyblargon commented 2 weeks ago

@lucian-tx honestly, pcie devices were never fully implemented in the proxmox-go-api library that the Terraform provider uses to connect to PVE. I have this on the roadmap for that library, but until it's reimplemented there, we can only really apply bandaid fixes in the Terraform provider. The Terraform provider should only require logic to map between its data structure and the library. The library is doing all the heavy lifting in when it comes to dealing with all the little quirks of PVE.

rafstef commented 1 week ago

after adding hostpci disk I receive the same error. are there some workaround ?

│ Error: Invalid address to set: []string{"hostpci", "0", "id"} │ │ with proxmox_vm_qemu.rke-node-pool[3], │ on worker_node.tf line 1, in resource "proxmox_vm_qemu" "rke-node-pool": │ 1: resource "proxmox_vm_qemu" "rke-node-pool" { │