diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cb25ead..6dbae1f2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,11 @@ { + "editor.bracketPairColorization.enabled": true, + "editor.guides.bracketPairs": true, + "editor.guides.bracketPairsHorizontal": true, + "editor.guides.highlightActiveBracketPair": true, + "editor.rulers": [ + 100 + ], "git.alwaysSignOff": true, "cSpell.words": [ "aarch", diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index 2ba87865..0e34d79d 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -87,6 +87,35 @@ func TestAccResourceVM(t *testing.T) { ), }}, }, + { + "update CPU block", []resource.TestStep{{ + Config: ` + resource "proxmox_virtual_environment_vm" "test_vm5" { + node_name = "pve" + started = false + + cpu { + cores = 2 + } + }`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm5", "cpu.0.cores", "2"), + ), + }, { + Config: ` + resource "proxmox_virtual_environment_vm" "test_vm5" { + node_name = "pve" + started = false + + cpu { + cores = 1 + } + }`, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("proxmox_virtual_environment_vm.test_vm5", "cpu.0.cores", "1"), + ), + }}, + }, } accProviders := testAccMuxProviders(context.Background(), t) diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index bf5925ef..db4660b0 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -4823,10 +4823,15 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D updateBody.CPUUnits = &cpuUnits updateBody.NUMAEnabled = &cpuNUMA - if cpuAffinity != "" { - updateBody.CPUAffinity = &cpuAffinity - } else { - del = append(del, "affinity") + // CPU affinity is a special case, only root can change it. + // we can't even have it in the delete list, as PVE will return an error for non-root. + // Hence, checking explicitly if it has changed. + if d.HasChange(mkCPU + ".0." + mkCPUAffinity) { + if cpuAffinity != "" { + updateBody.CPUAffinity = &cpuAffinity + } else { + del = append(del, "affinity") + } } if cpuHotplugged > 0 {