From cbc3a2d97e7a179c26e3770661099eb8a9e7aade Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Sun, 24 Nov 2024 00:21:51 +0100 Subject: [PATCH] fix: usb & pci devices not removed (#1169) --- proxmox/Internal/resource/guest/qemu/pci/sdk.go | 8 ++++++-- proxmox/Internal/resource/guest/qemu/usb/sdk.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/proxmox/Internal/resource/guest/qemu/pci/sdk.go b/proxmox/Internal/resource/guest/qemu/pci/sdk.go index d481aba6..95b21aa1 100644 --- a/proxmox/Internal/resource/guest/qemu/pci/sdk.go +++ b/proxmox/Internal/resource/guest/qemu/pci/sdk.go @@ -43,9 +43,13 @@ func SDK(d *schema.ResourceData) (pveAPI.QemuPciDevices, diag.Diagnostics) { if subSchema, ok := schemaItem[0].(map[string]interface{}); ok { for k, v := range subSchema { tmpID, _ := strconv.ParseUint(k[len(prefixSchemaID):], 10, 64) - pciDevices[pveAPI.QemuPciID(tmpID)] = sdkPCIs_Unsafe(v.([]interface{})) + pciDevices[pveAPI.QemuPciID(tmpID)] = sdkPCIs(v.([]interface{})) } } + } else { + for i := pveAPI.QemuPciID(0); i < pveAPI.QemuPciID(amountPCIs); i++ { + pciDevices[i] = pveAPI.QemuPci{Delete: true} + } } } return pciDevices, diags @@ -91,7 +95,7 @@ func sdkPCI(schema map[string]interface{}) (pveAPI.QemuPciID, pveAPI.QemuPci, er return id, pveAPI.QemuPci{Delete: true}, nil } -func sdkPCIs_Unsafe(schema []interface{}) pveAPI.QemuPci { +func sdkPCIs(schema []interface{}) pveAPI.QemuPci { if len(schema) == 0 { return pveAPI.QemuPci{Delete: true} } diff --git a/proxmox/Internal/resource/guest/qemu/usb/sdk.go b/proxmox/Internal/resource/guest/qemu/usb/sdk.go index 22313962..767b9457 100644 --- a/proxmox/Internal/resource/guest/qemu/usb/sdk.go +++ b/proxmox/Internal/resource/guest/qemu/usb/sdk.go @@ -42,6 +42,10 @@ func SDK(d *schema.ResourceData) (pveAPI.QemuUSBs, diag.Diagnostics) { usbDevices[pveAPI.QemuUsbID(tmpID)] = usbsSDK(v.([]interface{})) } } + } else { + for i := 0; i < amountUSBs; i++ { + usbDevices[pveAPI.QemuUsbID(i)] = pveAPI.QemuUSB{Delete: true} + } } } return usbDevices, diags