From aa939c731f7bc36213b6d0abc51cc284a1295338 Mon Sep 17 00:00:00 2001 From: Michael Iseli Date: Mon, 18 Dec 2023 04:28:33 +0100 Subject: [PATCH] fix(vm): hostpci devices not showing up in refresh plan (#578) * bug(vm): fix hostpci devices not showing up in refresh plan Signed-off-by: Michael Iseli * fix pci & usb devices set on read, fix test Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Michael Iseli Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/nodes/vms/vms_types_test.go | 8 ++------ proxmoxtf/resource/vm.go | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/proxmox/nodes/vms/vms_types_test.go b/proxmox/nodes/vms/vms_types_test.go index 81747d9f..4a44fbc8 100644 --- a/proxmox/nodes/vms/vms_types_test.go +++ b/proxmox/nodes/vms/vms_types_test.go @@ -133,12 +133,7 @@ func TestCustomPCIDevice_UnmarshalJSON(t *testing.T) { name: "id only pci device", line: `"0000:81:00.2"`, want: &CustomPCIDevice{ - DeviceIDs: &[]string{"0000:81:00.2"}, - MDev: nil, - PCIExpress: types.BoolPtr(false), - ROMBAR: types.BoolPtr(true), - ROMFile: nil, - XVGA: types.BoolPtr(false), + DeviceIDs: &[]string{"0000:81:00.2"}, }, }, { @@ -176,6 +171,7 @@ func TestCustomPCIDevice_UnmarshalJSON(t *testing.T) { if err := r.UnmarshalJSON([]byte(tt.line)); (err != nil) != tt.wantErr { t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) } + require.Equal(t, tt.want, r) }) } } diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index e00cdd4e..db021dd9 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -4364,7 +4364,7 @@ func vmReadCustom( if pp.ROMBAR != nil { pci[mkResourceVirtualEnvironmentVMHostPCIDeviceROMBAR] = *pp.ROMBAR } else { - pci[mkResourceVirtualEnvironmentVMHostPCIDeviceROMBAR] = false + pci[mkResourceVirtualEnvironmentVMHostPCIDeviceROMBAR] = true } if pp.ROMFile != nil { @@ -4388,7 +4388,7 @@ func vmReadCustom( pciMap[pi] = pci } - if len(currentPCIList) > 0 { + if len(clone) == 0 || len(currentPCIList) > 0 { orderedPCIList := orderedListFromMap(pciMap) err := d.Set(mkResourceVirtualEnvironmentVMHostPCI, orderedPCIList) diags = append(diags, diag.FromErr(err)...) @@ -4426,7 +4426,7 @@ func vmReadCustom( usbMap[pi] = usb } - if len(currentUSBList) > 0 { + if len(clone) == 0 || len(currentUSBList) > 0 { // todo: reordering of devices by PVE may cause an issue here orderedUSBList := orderedListFromMap(usbMap) err := d.Set(mkResourceVirtualEnvironmentVMHostUSB, orderedUSBList)