From a038fd31420fe23963c7d68198ed5f40b6583058 Mon Sep 17 00:00:00 2001 From: Michael Iseli Date: Mon, 21 Aug 2023 01:01:19 +0200 Subject: [PATCH] feat(vm): fix adding/removing hostpci devices forcing vm recreation (#504) * feat(vm): fix adding/removing hostpci devices forcing vm recreation * fix: hostpci device removal * fix: hostpci jason unmarshalling but introduced in #500 --------- Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/nodes/vms/vms_types.go | 2 +- proxmoxtf/resource/vm.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index 0eccbab5..dc4d99eb 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -1622,7 +1622,7 @@ func (r *CustomPCIDevice) UnmarshalJSON(b []byte) error { } else if len(v) == 2 { switch v[0] { case "host": - dIds := strings.Split(v[0], ";") + dIds := strings.Split(v[1], ";") r.DeviceIDs = &dIds case "mapping": r.Mapping = &v[1] diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index 35510cf9..428e80a3 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -137,6 +137,7 @@ const ( maxResourceVirtualEnvironmentVMAudioDevices = 1 maxResourceVirtualEnvironmentVMNetworkDevices = 8 maxResourceVirtualEnvironmentVMSerialDevices = 4 + maxResourceVirtualEnvironmentVMHostPCIDevices = 8 mkResourceVirtualEnvironmentVMRebootAfterCreation = "reboot" mkResourceVirtualEnvironmentVMOnBoot = "on_boot" @@ -998,7 +999,7 @@ func VM() *schema.Resource { Type: schema.TypeList, Description: "The Host PCI devices mapped to the VM", Optional: true, - ForceNew: true, + ForceNew: false, DefaultFunc: func() (interface{}, error) { return []interface{}{}, nil }, @@ -5300,6 +5301,11 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D // Prepare the new hostpci devices configuration. if d.HasChange(mkResourceVirtualEnvironmentVMHostPCI) { updateBody.PCIDevices = vmGetHostPCIDeviceObjects(d) + + for i := len(updateBody.PCIDevices); i < maxResourceVirtualEnvironmentVMHostPCIDevices; i++ { + del = append(del, fmt.Sprintf("hostpci%d", i)) + } + rebootRequired = true }