0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-03 12:02:57 +00:00

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>
This commit is contained in:
Michael Iseli 2023-08-21 01:01:19 +02:00 committed by GitHub
parent 26970541c4
commit a038fd3142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -1622,7 +1622,7 @@ func (r *CustomPCIDevice) UnmarshalJSON(b []byte) error {
} else if len(v) == 2 { } else if len(v) == 2 {
switch v[0] { switch v[0] {
case "host": case "host":
dIds := strings.Split(v[0], ";") dIds := strings.Split(v[1], ";")
r.DeviceIDs = &dIds r.DeviceIDs = &dIds
case "mapping": case "mapping":
r.Mapping = &v[1] r.Mapping = &v[1]

View File

@ -137,6 +137,7 @@ const (
maxResourceVirtualEnvironmentVMAudioDevices = 1 maxResourceVirtualEnvironmentVMAudioDevices = 1
maxResourceVirtualEnvironmentVMNetworkDevices = 8 maxResourceVirtualEnvironmentVMNetworkDevices = 8
maxResourceVirtualEnvironmentVMSerialDevices = 4 maxResourceVirtualEnvironmentVMSerialDevices = 4
maxResourceVirtualEnvironmentVMHostPCIDevices = 8
mkResourceVirtualEnvironmentVMRebootAfterCreation = "reboot" mkResourceVirtualEnvironmentVMRebootAfterCreation = "reboot"
mkResourceVirtualEnvironmentVMOnBoot = "on_boot" mkResourceVirtualEnvironmentVMOnBoot = "on_boot"
@ -998,7 +999,7 @@ func VM() *schema.Resource {
Type: schema.TypeList, Type: schema.TypeList,
Description: "The Host PCI devices mapped to the VM", Description: "The Host PCI devices mapped to the VM",
Optional: true, Optional: true,
ForceNew: true, ForceNew: false,
DefaultFunc: func() (interface{}, error) { DefaultFunc: func() (interface{}, error) {
return []interface{}{}, nil 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. // Prepare the new hostpci devices configuration.
if d.HasChange(mkResourceVirtualEnvironmentVMHostPCI) { if d.HasChange(mkResourceVirtualEnvironmentVMHostPCI) {
updateBody.PCIDevices = vmGetHostPCIDeviceObjects(d) updateBody.PCIDevices = vmGetHostPCIDeviceObjects(d)
for i := len(updateBody.PCIDevices); i < maxResourceVirtualEnvironmentVMHostPCIDevices; i++ {
del = append(del, fmt.Sprintf("hostpci%d", i))
}
rebootRequired = true rebootRequired = true
} }