Skip to content

Commit

Permalink
fix(vm): regressions: provider always tries to update cpu.affinity
Browse files Browse the repository at this point in the history
…even if it is not specified (#1182)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
  • Loading branch information
bpg committed Apr 4, 2024
1 parent 39e67da commit 82d435f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 29 additions & 0 deletions fwprovider/tests/resource_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions proxmoxtf/resource/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 82d435f

Please sign in to comment.