0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 19:12:59 +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 {
switch v[0] {
case "host":
dIds := strings.Split(v[0], ";")
dIds := strings.Split(v[1], ";")
r.DeviceIDs = &dIds
case "mapping":
r.Mapping = &v[1]

View File

@ -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
}