0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-08-23 03:48:35 +00:00

Ignore default value for cpu.architecture when the root account is not being used

This commit is contained in:
Dan Petersen 2020-03-27 16:57:54 +01:00
parent c41fb7c3b9
commit 5099ff372c
3 changed files with 39 additions and 6 deletions

View File

@ -1,9 +1,13 @@
## 0.4.0
## 0.4.0 (UNRELEASED)
BUG FIXES:
* library/virtual_environment_nodes: Fix node IP address format
WORKAROUNDS:
* resource/virtual_environment_vm: Ignore default value for `cpu.architecture` when the root account is not being used
## 0.3.0
ENHANCEMENTS:

View File

@ -13,6 +13,11 @@ import (
"net/url"
)
const (
// DefaultRootAccount contains the default username and realm for the root account.
DefaultRootAccount = "root@pam"
)
// Authenticate authenticates against the specified endpoint.
func (c *VirtualEnvironmentClient) Authenticate(reset bool) error {
if c.authenticationData != nil && !reset {

View File

@ -1129,7 +1129,11 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
cpuFlagsConverted[fi] = flag.(string)
}
// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if veClient.Username == proxmox.DefaultRootAccount || cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
updateBody.CPUArchitecture = &cpuArchitecture
}
updateBody.CPUCores = &cpuCores
updateBody.CPUEmulation = &proxmox.CustomCPUEmulation{
Flags: &cpuFlagsConverted,
@ -1458,7 +1462,6 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
BootDisk: &bootDisk,
BootOrder: &bootOrder,
CloudInitConfig: initializationConfig,
CPUArchitecture: &cpuArchitecture,
CPUCores: &cpuCores,
CPUEmulation: &proxmox.CustomCPUEmulation{
Flags: &cpuFlagsConverted,
@ -1484,6 +1487,11 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
VMID: &vmID,
}
// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if veClient.Username == proxmox.DefaultRootAccount || cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
createBody.CPUArchitecture = &cpuArchitecture
}
if cpuHotplugged > 0 {
createBody.VirtualCPUCount = &cpuHotplugged
}
@ -2037,7 +2045,14 @@ func resourceVirtualEnvironmentVMRead(d *schema.ResourceData, m interface{}) err
}
func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{}, vmID int, vmConfig *proxmox.VirtualEnvironmentVMGetResponseData, vmStatus *proxmox.VirtualEnvironmentVMGetStatusResponseData) error {
err := resourceVirtualEnvironmentVMReadPrimitiveValues(d, m, vmID, vmConfig, vmStatus)
config := m.(providerConfiguration)
veClient, err := config.GetVEClient()
if err != nil {
return err
}
err = resourceVirtualEnvironmentVMReadPrimitiveValues(d, m, vmID, vmConfig, vmStatus)
if err != nil {
return err
@ -2178,8 +2193,13 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = *vmConfig.CPUArchitecture
} else {
// Default value of "arch" is "" according to the API documentation.
// However, assume the provider's default value as a workaround when the root account is not being used.
if veClient.Username != proxmox.DefaultRootAccount {
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = dvResourceVirtualEnvironmentVMCPUArchitecture
} else {
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = ""
}
}
if vmConfig.CPUCores != nil {
cpu[mkResourceVirtualEnvironmentVMCPUCores] = *vmConfig.CPUCores
@ -3047,7 +3067,11 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
cpuType := cpuBlock[mkResourceVirtualEnvironmentVMCPUType].(string)
cpuUnits := cpuBlock[mkResourceVirtualEnvironmentVMCPUUnits].(int)
// Only the root account is allowed to change the CPU architecture, which makes this check necessary.
if veClient.Username == proxmox.DefaultRootAccount || cpuArchitecture != dvResourceVirtualEnvironmentVMCPUArchitecture {
updateBody.CPUArchitecture = &cpuArchitecture
}
updateBody.CPUCores = &cpuCores
updateBody.CPUSockets = &cpuSockets
updateBody.CPUUnits = &cpuUnits