From 9ea1cdba2cfacfc5d258f36c590811191480c663 Mon Sep 17 00:00:00 2001 From: Dan Petersen Date: Tue, 31 Dec 2019 06:25:40 +0100 Subject: [PATCH] Fixed vCPU update issue --- proxmox/virtual_environment_vm_types.go | 1 + proxmoxtf/resource_virtual_environment_vm.go | 28 ++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/proxmox/virtual_environment_vm_types.go b/proxmox/virtual_environment_vm_types.go index f852fc6b..9c9f407c 100644 --- a/proxmox/virtual_environment_vm_types.go +++ b/proxmox/virtual_environment_vm_types.go @@ -216,6 +216,7 @@ type VirtualEnvironmentVMCreateRequestBody struct { CPUSockets *int `json:"sockets,omitempty" url:"sockets,omitempty"` CPUUnits *int `json:"cpuunits,omitempty" url:"cpuunits,omitempty"` DedicatedMemory *int `json:"memory,omitempty" url:"memory,omitempty"` + Delete []string `json:"delete,omitempty" url:"delete,omitempty,comma"` DeletionProtection *CustomBool `json:"protection,omitempty" url:"force,omitempty,int"` Description *string `json:"description,omitempty" url:"description,omitempty"` EFIDisk *CustomEFIDisk `json:"efidisk0,omitempty" url:"efidisk0,omitempty"` diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index 501a3745..8ded7cee 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -2013,6 +2013,7 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e } // Prepare the new primitive configuration values. + delete := []string{} description := d.Get(mkResourceVirtualEnvironmentVMDescription).(string) keyboardLayout := d.Get(mkResourceVirtualEnvironmentVMKeyboardLayout).(string) name := d.Get(mkResourceVirtualEnvironmentVMName).(string) @@ -2113,29 +2114,20 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e } cpuCores := cpuBlock[mkResourceVirtualEnvironmentVMCPUCores].(int) - - if cpuCores > 0 { - body.CPUCores = &cpuCores - } - cpuFlags := cpuBlock[mkResourceVirtualEnvironmentVMCPUFlags].([]interface{}) cpuHotplugged := cpuBlock[mkResourceVirtualEnvironmentVMCPUHotplugged].(int) - - if cpuHotplugged > 0 { - body.VirtualCPUCount = &cpuHotplugged - } - cpuSockets := cpuBlock[mkResourceVirtualEnvironmentVMCPUSockets].(int) - - if cpuSockets > 0 { - body.CPUSockets = &cpuSockets - } - cpuType := cpuBlock[mkResourceVirtualEnvironmentVMCPUType].(string) cpuUnits := cpuBlock[mkResourceVirtualEnvironmentVMCPUUnits].(int) - if cpuUnits > 0 { - body.CPUUnits = &cpuUnits + body.CPUCores = &cpuCores + body.CPUSockets = &cpuSockets + body.CPUUnits = &cpuUnits + + if cpuHotplugged > 0 { + body.VirtualCPUCount = &cpuHotplugged + } else { + delete = append(delete, "vcpus") } cpuFlagsConverted := make([]string, len(cpuFlags)) @@ -2244,6 +2236,8 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e } // Update the configuration now that everything has been prepared. + body.Delete = delete + err = veClient.UpdateVM(nodeName, vmID, body) if err != nil {