mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-23 03:48:35 +00:00
Merge pull request #11 from danitso/workaround-vm-cpu-architecture-permissions
Ignore default value for cpu.architecture when the root account is not being used
This commit is contained in:
commit
b1d16d641a
@ -1,9 +1,13 @@
|
|||||||
## 0.4.0
|
## 0.4.0 (UNRELEASED)
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
||||||
* library/virtual_environment_nodes: Fix node IP address format
|
* 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
|
## 0.3.0
|
||||||
|
|
||||||
ENHANCEMENTS:
|
ENHANCEMENTS:
|
||||||
|
@ -13,6 +13,11 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultRootAccount contains the default username and realm for the root account.
|
||||||
|
DefaultRootAccount = "root@pam"
|
||||||
|
)
|
||||||
|
|
||||||
// Authenticate authenticates against the specified endpoint.
|
// Authenticate authenticates against the specified endpoint.
|
||||||
func (c *VirtualEnvironmentClient) Authenticate(reset bool) error {
|
func (c *VirtualEnvironmentClient) Authenticate(reset bool) error {
|
||||||
if c.authenticationData != nil && !reset {
|
if c.authenticationData != nil && !reset {
|
||||||
|
@ -1129,7 +1129,11 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
cpuFlagsConverted[fi] = flag.(string)
|
cpuFlagsConverted[fi] = flag.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBody.CPUArchitecture = &cpuArchitecture
|
// 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.CPUCores = &cpuCores
|
||||||
updateBody.CPUEmulation = &proxmox.CustomCPUEmulation{
|
updateBody.CPUEmulation = &proxmox.CustomCPUEmulation{
|
||||||
Flags: &cpuFlagsConverted,
|
Flags: &cpuFlagsConverted,
|
||||||
@ -1458,7 +1462,6 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
|||||||
BootDisk: &bootDisk,
|
BootDisk: &bootDisk,
|
||||||
BootOrder: &bootOrder,
|
BootOrder: &bootOrder,
|
||||||
CloudInitConfig: initializationConfig,
|
CloudInitConfig: initializationConfig,
|
||||||
CPUArchitecture: &cpuArchitecture,
|
|
||||||
CPUCores: &cpuCores,
|
CPUCores: &cpuCores,
|
||||||
CPUEmulation: &proxmox.CustomCPUEmulation{
|
CPUEmulation: &proxmox.CustomCPUEmulation{
|
||||||
Flags: &cpuFlagsConverted,
|
Flags: &cpuFlagsConverted,
|
||||||
@ -1484,6 +1487,11 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
|||||||
VMID: &vmID,
|
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 {
|
if cpuHotplugged > 0 {
|
||||||
createBody.VirtualCPUCount = &cpuHotplugged
|
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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -2178,7 +2193,12 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{
|
|||||||
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = *vmConfig.CPUArchitecture
|
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = *vmConfig.CPUArchitecture
|
||||||
} else {
|
} else {
|
||||||
// Default value of "arch" is "" according to the API documentation.
|
// Default value of "arch" is "" according to the API documentation.
|
||||||
cpu[mkResourceVirtualEnvironmentVMCPUArchitecture] = ""
|
// 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 {
|
if vmConfig.CPUCores != nil {
|
||||||
@ -3047,7 +3067,11 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
|||||||
cpuType := cpuBlock[mkResourceVirtualEnvironmentVMCPUType].(string)
|
cpuType := cpuBlock[mkResourceVirtualEnvironmentVMCPUType].(string)
|
||||||
cpuUnits := cpuBlock[mkResourceVirtualEnvironmentVMCPUUnits].(int)
|
cpuUnits := cpuBlock[mkResourceVirtualEnvironmentVMCPUUnits].(int)
|
||||||
|
|
||||||
updateBody.CPUArchitecture = &cpuArchitecture
|
// 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.CPUCores = &cpuCores
|
||||||
updateBody.CPUSockets = &cpuSockets
|
updateBody.CPUSockets = &cpuSockets
|
||||||
updateBody.CPUUnits = &cpuUnits
|
updateBody.CPUUnits = &cpuUnits
|
||||||
|
Loading…
Reference in New Issue
Block a user