0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 18:42:58 +00:00

fix(vm): regressions: provider always tries to update cpu.affinity even if it is not specified (#1182)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-04-04 19:48:49 -04:00 committed by GitHub
parent 39e67da544
commit 82d435f575
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 4 deletions

View File

@ -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",

View File

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

View File

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