From c20d79dfbe34b4f161d49a6c9b595354444bacd9 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:25:40 -0400 Subject: [PATCH] fix(vm): `cpu.architecture` showed as new attribute at re-apply after creation (#1524) Fix for another use case of mismanaged default value. This one was a bit trickier to spot as it triggered only when provider is authenticated using root@pam, as architecture change is allowed only for root. Removing default value altogether, as the PVE API default for this attribute is an empty string. VM2 resource will have no such issue, related: #1310, #1311 Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmoxtf/resource/vm/validators.go | 1 + proxmoxtf/resource/vm/vm.go | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/proxmoxtf/resource/vm/validators.go b/proxmoxtf/resource/vm/validators.go index 9bf6940c..f1a5905b 100644 --- a/proxmoxtf/resource/vm/validators.go +++ b/proxmoxtf/resource/vm/validators.go @@ -55,6 +55,7 @@ func BIOSValidator() schema.SchemaValidateDiagFunc { // CPUArchitectureValidator returns a schema validation function for a CPU architecture. func CPUArchitectureValidator() schema.SchemaValidateDiagFunc { return validation.ToDiagFunc(validation.StringInSlice([]string{ + "", "aarch64", "x86_64", }, false)) diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 9cf8b8ab..862eaa1b 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -58,7 +58,7 @@ const ( dvCloneNodeName = "" dvCloneFull = true dvCloneRetries = 1 - dvCPUArchitecture = "x86_64" + dvCPUArchitecture = "" dvCPUCores = 1 dvCPUHotplugged = 0 dvCPULimit = 0 @@ -1890,8 +1890,7 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d } // Only the root account is allowed to change the CPU architecture, which makes this check necessary. - if client.API().IsRootTicket() || - cpuArchitecture != dvCPUArchitecture { + if client.API().IsRootTicket() && cpuArchitecture != "" { updateBody.CPUArchitecture = &cpuArchitecture } @@ -2574,8 +2573,7 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{}) } // Only the root account is allowed to change the CPU architecture, which makes this check necessary. - if client.API().IsRootTicket() || - cpuArchitecture != dvCPUArchitecture { + if client.API().IsRootTicket() && cpuArchitecture != "" { createBody.CPUArchitecture = &cpuArchitecture } @@ -4845,8 +4843,7 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D cpuAffinity := cpuBlock[mkCPUAffinity].(string) // Only the root account is allowed to change the CPU architecture, which makes this check necessary. - if client.API().IsRootTicket() || - cpuArchitecture != dvCPUArchitecture { + if client.API().IsRootTicket() && cpuArchitecture != "" { updateBody.CPUArchitecture = &cpuArchitecture }