Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.11k stars 510 forks source link

[3.0.1-rc2] Error refresh state USB passthrough device #1032

Open den-patrakeev opened 3 months ago

den-patrakeev commented 3 months ago

Hi, migrates from 3.0.1-rc1 to 3.0.1-rc2 and fix error with USB passthrough device.

Proxmox VE cluster with version nodes: 8.0.4 and 8.2.2 Terraform - 1.8.4

USB manually config in VM by root and fix in .tfstate by terraform refresh. Ignore changes in state VM from provider by this:

  lifecycle {
    ignore_changes = [
      usb
    ]
  }

In new version 3.0.1-rc2 error by terraform refresh or terraform plan:

│ Error: Invalid address to set: []string{"usb", "0", "id"}
│ 
│   with proxmox_vm_qemu._101_xxx,
│   on 101_xxx.tf line 3, in resource "proxmox_vm_qemu" "_101_xxx":
│    3: resource "proxmox_vm_qemu" "_101_xxx" {
maksimsamt commented 3 months ago

Try this ignore_changes:

...
    ignore_changes = [
      usb[0]
    ]
...

or

...
    ignore_changes = [
      usb[0].host
      usb[0].usb3
    ]
...
den-patrakeev commented 3 months ago

Try this ignore_changes:

...
    ignore_changes = [
      usb[0]
    ]
...

or

...
    ignore_changes = [
      usb[0].host
      usb[0].usb3
    ]
...

Hi! Thank you! Unfortunately this didn't help.

maksimsamt commented 3 months ago

Hi! Thank you! Unfortunately this didn't help.

Can you share your config snippet with usb block/blocks?

Aksogen commented 3 months ago

The same error with hostpci section Invalid address to set: []string{"hostpci", "0", "id"}

block:

    dynamic hostpci {
        for_each = var.vm_pci_devices
        content {
            host   = hostpci.value.id
            rombar = hostpci.value.rombar
            pcie   = hostpci.value.pcie
        }
    }
    vm_pci_devices = [
        { id = "0000:00:02", rombar = 1, pcie = 0 }
    ]
maksimsamt commented 3 months ago

The same error with hostpci section Invalid address to set: []string{"hostpci", "0", "id"}

block:

    dynamic hostpci {
        for_each = var.vm_pci_devices
        content {
            host   = hostpci.value.id
            rombar = hostpci.value.rombar
            pcie   = hostpci.value.pcie
        }
    }
    vm_pci_devices = [
        { id = "0000:00:02", rombar = 1, pcie = 0 }
    ]

1) I'm not sure if you're using Terraform dynamic blocks correctly.

...
dynamic hostpci {
...

As per Terraform documentation it should be like this:

...
dynamic "hostpci" {
...

2) Are you sure the latest version of the provider supports hostpci?

I couldn't find anything similar in Temate provider documentation

Aksogen commented 3 months ago
  1. you can use both variants: example of working dynamic block (network)
    dynamic network {
        for_each = var.vm_network_interfaces
        content {
            bridge   = network.value.bridge
            model    = network.value.model
            firewall = network.value.firewall
            tag      = network.value.vlan        
        }
    }
  1. So..it worked before, and it didn't say in the change notes that it no longer works :| hostpci block was added in v2.9.14 (https://github.com/Telmate/terraform-provider-proxmox/issues/299)

(anyway it present in https://github.com/Telmate/terraform-provider-proxmox/blob/d3fed178e06e9429e27e92094387e1ceef95e825/proxmox/resource_vm_qemu.go#L437 )

maksimsamt commented 3 months ago
  1. you can use both variants: example of working dynamic block (network)
    dynamic network {
        for_each = var.vm_network_interfaces
        content {
            bridge   = network.value.bridge
            model    = network.value.model
            firewall = network.value.firewall
            tag      = network.value.vlan        
        }
    }
  1. So..it worked before, and it didn't say in the change notes that it no longer works :| hostpci block was added in v2.9.14 (How to enable PCI passthrough #299)

(anyway it present in

https://github.com/Telmate/terraform-provider-proxmox/blob/d3fed178e06e9429e27e92094387e1ceef95e825/proxmox/resource_vm_qemu.go#L437

)

  1. OK, but there is no official documentation that this can be done un such way...

  2. Latest major version is v3, not v2 Present - doesn't mean that it really works :) and at the same time there is no documentation for this... Here it is necessary to get comments from the developers.

den-patrakeev commented 3 months ago

Hi! Thank you! Unfortunately this didn't help.

Can you share your config snippet with usb block/blocks?

Block with USB commented out and don`t use.

Cause: User for provider on ProxMox VE cluster has no rights for configure USB passthrought. USB configuration is available only to the user root. This is a limitation ProxMox VE.

Therefore, we set it up manually and ignore USB in config provider.

Uncommenting the block gives the same error.

maksimsamt commented 3 months ago

Block with USB commented out and don`t use. Therefore, we set it up manually and ignore USB in config provider. Uncommenting the block gives the same error.

Seems something you are doing wrong... Unfortunately, without all the details I can’t say what exactly is wrong.

User for provider on ProxMox VE cluster has no rights for configure USB passthrought. USB configuration is available only to the user root. This is a limitation ProxMox VE.

As for this, check and try out this Proxmox Forum thread:

Only root@pam is now allowed to clone and restore guests with passed through PCI/USB devices that are not using the new mapping feature. To allow regular users to clone and restore with PCI/USB devices, create a mapping and give the user 'Mapping.Use' on that.

You can try as well use other Mapping privileges for that:

Mapping.Audit: view resource mappings
Mapping.Modify: manage resource mappings
Mapping.Use: use resource mappings
den-patrakeev commented 3 months ago

@maksimsamt Thanks for the information about the directive Mapping.Use! I'll try it and post the results.

baltazorbest commented 3 months ago

Hello. After updating from version 3.0.1-rc1 to version 3.0.1-rc3, I encountered the same error for VMs to which I added PCI-e device mapping. How can I add an ignore rule for devices that I added myself?

I tried this one:

  lifecycle {
    ignore_changes = [
      hostpci,
    ]
  }

But the error is stilling.

dsander commented 2 months ago

I am getting the same error when using usb like it's documented:

  usb {
    host = "051d:0002"
    usb3 = false
  }

Did some bisecting of the plugin and is the commit that introduced the change: https://github.com/Telmate/terraform-provider-proxmox/commit/819869a1c9f337fc940f1b97613d7b5d8fd11c9c. I don't know the code, maybe before the change the data from the proxmox API was just ignored and never put into the state because it didn't/doesn't match the expected format?

psychodracon commented 1 month ago

Hello, any news on that? I've created machine using root account for authentication everything worked as expected including usb creation but after that i can no longer run terraform refresh or terraform plan because of the same error. I've already tried adding different combinations to ignore_changes block but none of them is working

otwieracz commented 1 month ago

Same here:

Error: Invalid address to set: []string{"usb", "0", "id"}

Does not matter if I add the USB passthrough through the webui or the TF itself.

den-patrakeev commented 1 month ago

@maksimsamt

Block with USB commented out and don`t use. Therefore, we set it up manually and ignore USB in config provider. Uncommenting the block gives the same error.

Seems something you are doing wrong... Unfortunately, without all the details I can’t say what exactly is wrong.

User for provider on ProxMox VE cluster has no rights for configure USB passthrought. USB configuration is available only to the user root. This is a limitation ProxMox VE.

As for this, check and try out this Proxmox Forum thread:

Only root@pam is now allowed to clone and restore guests with passed through PCI/USB devices that are not using the new mapping feature. To allow regular users to clone and restore with PCI/USB devices, create a mapping and give the user 'Mapping.Use' on that.

You can try as well use other Mapping privileges for that:

Mapping.Audit: view resource mappings
Mapping.Modify: manage resource mappings
Mapping.Use: use resource mappings

Hi! Sorry for the long wait.

Adding user for terraform provirder access:

Mapping.Audit: view resource mappings
Mapping.Modify: manage resource mappings
Mapping.Use: use resource mappings

didn't help.

Regardless of whether the block is commented out or not. And also whether usb is added to ignore or not. Tried to manually clear the USB information in the .tfstate file.

The error persists and Terraform cannot refresh.

rwburgman commented 3 weeks ago

@lucian-tx fixed a similar issue for the hostpci config. I applied the same path to usb devices in #1077, which fixes this issue for me.

tuxthepenguin84 commented 3 weeks ago

@lucian-tx fixed a similar issue for the hostpci config. I applied the same path to usb devices in #1077, which fixes this issue for me.

Thanks, this fixed it for me.

zoechi commented 1 week ago

I just tried it and I don't get this error anymore: Error: Invalid address to set: []string{"usb", "0", "id"}

The only change I'm aware of is updating the proxmox terraform provider to version 3.0.1-rc4