From e2802d0654f0d6d5e99bef4987a84862e3ffbde7 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 5 Feb 2023 23:18:47 -0500 Subject: [PATCH] fix(vm): Fix handling of empty kvm arguments (#228) * fix(vm): Fix false detection of a changed VM state when KVM arguments is empty PVE returns a single space string (`" "`) when KVM arguments are not set. * fix(vm): set KVM arguments only if non-empty --- proxmoxtf/resource_virtual_environment_vm.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index fd8566d3..bcec0b00 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -1977,7 +1977,6 @@ func resourceVirtualEnvironmentVMCreateCustom( FloatingMemory: &memoryFloating, IDEDevices: ideDevices, KeyboardLayout: &keyboardLayout, - KVMArguments: &kvmArguments, NetworkDevices: networkDeviceObjects, OSType: &operatingSystemType, PCIDevices: pciDeviceObjects, @@ -2022,6 +2021,10 @@ func resourceVirtualEnvironmentVMCreateCustom( createBody.Tags = &tagsString } + if kvmArguments != "" { + createBody.KVMArguments = &kvmArguments + } + if machine != "" { createBody.Machine = &machine } @@ -3754,7 +3757,8 @@ func resourceVirtualEnvironmentVMReadPrimitiveValues( currentkvmArguments := d.Get(mkResourceVirtualEnvironmentVMKVMArguments).(string) if len(clone) == 0 || currentkvmArguments != dvResourceVirtualEnvironmentVMKVMArguments { - if vmConfig.KVMArguments != nil { + // PVE API returns "args" as " " if it is set to empty. + if vmConfig.KVMArguments != nil && len(strings.TrimSpace(*vmConfig.KVMArguments)) > 0 { err = d.Set(mkResourceVirtualEnvironmentVMKVMArguments, *vmConfig.KVMArguments) } else { // Default value of "args" is "" according to the API documentation.