mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-23 11:58:34 +00:00
Resolves cloud init disk conflict with cdrom
This commit is contained in:
parent
3e6eb46905
commit
e9528546c8
@ -368,6 +368,7 @@ type VirtualEnvironmentVMGetResponseData struct {
|
|||||||
IDEDevice0 *CustomStorageDevice `json:"ide0,omitempty"`
|
IDEDevice0 *CustomStorageDevice `json:"ide0,omitempty"`
|
||||||
IDEDevice1 *CustomStorageDevice `json:"ide1,omitempty"`
|
IDEDevice1 *CustomStorageDevice `json:"ide1,omitempty"`
|
||||||
IDEDevice2 *CustomStorageDevice `json:"ide2,omitempty"`
|
IDEDevice2 *CustomStorageDevice `json:"ide2,omitempty"`
|
||||||
|
IDEDevice3 *CustomStorageDevice `json:"ide3,omitempty"`
|
||||||
IPConfig0 *CustomCloudInitIPConfig `json:"ipconfig0,omitempty"`
|
IPConfig0 *CustomCloudInitIPConfig `json:"ipconfig0,omitempty"`
|
||||||
IPConfig1 *CustomCloudInitIPConfig `json:"ipconfig1,omitempty"`
|
IPConfig1 *CustomCloudInitIPConfig `json:"ipconfig1,omitempty"`
|
||||||
IPConfig2 *CustomCloudInitIPConfig `json:"ipconfig2,omitempty"`
|
IPConfig2 *CustomCloudInitIPConfig `json:"ipconfig2,omitempty"`
|
||||||
|
@ -1061,6 +1061,8 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
AudioDevices: audioDevices,
|
AudioDevices: audioDevices,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ideDevices := proxmox.CustomStorageDevices{}
|
||||||
|
|
||||||
delete := []string{}
|
delete := []string{}
|
||||||
|
|
||||||
if acpi != dvResourceVirtualEnvironmentVMACPI {
|
if acpi != dvResourceVirtualEnvironmentVMACPI {
|
||||||
@ -1085,6 +1087,23 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
updateBody.BIOS = &bios
|
updateBody.BIOS = &bios
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cdrom) > 0 || len(initialization) > 0 {
|
||||||
|
ideDevices = proxmox.CustomStorageDevices{
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: false,
|
||||||
|
},
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: false,
|
||||||
|
},
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: false,
|
||||||
|
},
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(cdrom) > 0 {
|
if len(cdrom) > 0 {
|
||||||
cdromBlock := cdrom[0].(map[string]interface{})
|
cdromBlock := cdrom[0].(map[string]interface{})
|
||||||
|
|
||||||
@ -1097,19 +1116,13 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
|
|
||||||
cdromMedia := "cdrom"
|
cdromMedia := "cdrom"
|
||||||
|
|
||||||
updateBody.IDEDevices = proxmox.CustomStorageDevices{
|
cdromDevice := proxmox.CustomStorageDevice{
|
||||||
proxmox.CustomStorageDevice{
|
|
||||||
Enabled: false,
|
|
||||||
},
|
|
||||||
proxmox.CustomStorageDevice{
|
|
||||||
Enabled: false,
|
|
||||||
},
|
|
||||||
proxmox.CustomStorageDevice{
|
|
||||||
Enabled: cdromEnabled,
|
Enabled: cdromEnabled,
|
||||||
FileVolume: cdromFileID,
|
FileVolume: cdromFileID,
|
||||||
Media: &cdromMedia,
|
Media: &cdromMedia,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ideDevices[3] = cdromDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cpu) > 0 {
|
if len(cpu) > 0 {
|
||||||
@ -1151,24 +1164,17 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
initializationBlock := initialization[0].(map[string]interface{})
|
initializationBlock := initialization[0].(map[string]interface{})
|
||||||
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
||||||
|
|
||||||
cdromEnabled := true
|
cdromCloudInitEnabled := true
|
||||||
cdromFileID := fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
cdromCloudInitFileID := fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||||
cdromMedia := "cdrom"
|
cdromCloudInitMedia := "cdrom"
|
||||||
|
|
||||||
updateBody.IDEDevices = proxmox.CustomStorageDevices{
|
cdromCloudInitDevice := proxmox.CustomStorageDevice{
|
||||||
proxmox.CustomStorageDevice{
|
Enabled: cdromCloudInitEnabled,
|
||||||
Enabled: false,
|
FileVolume: cdromCloudInitFileID,
|
||||||
},
|
Media: &cdromCloudInitMedia,
|
||||||
proxmox.CustomStorageDevice{
|
|
||||||
Enabled: false,
|
|
||||||
},
|
|
||||||
proxmox.CustomStorageDevice{
|
|
||||||
Enabled: cdromEnabled,
|
|
||||||
FileVolume: cdromFileID,
|
|
||||||
Media: &cdromMedia,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ideDevices[2] = cdromCloudInitDevice
|
||||||
initializationConfig, err := resourceVirtualEnvironmentVMGetCloudInitConfig(d, m)
|
initializationConfig, err := resourceVirtualEnvironmentVMGetCloudInitConfig(d, m)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1178,6 +1184,10 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
|||||||
updateBody.CloudInitConfig = initializationConfig
|
updateBody.CloudInitConfig = initializationConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cdrom) > 0 || len(initialization) > 0 {
|
||||||
|
updateBody.IDEDevices = ideDevices
|
||||||
|
}
|
||||||
|
|
||||||
if keyboardLayout != dvResourceVirtualEnvironmentVMKeyboardLayout {
|
if keyboardLayout != dvResourceVirtualEnvironmentVMKeyboardLayout {
|
||||||
updateBody.KeyboardLayout = &keyboardLayout
|
updateBody.KeyboardLayout = &keyboardLayout
|
||||||
}
|
}
|
||||||
@ -1311,6 +1321,9 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
|||||||
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
||||||
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
||||||
|
|
||||||
|
cdromCloudInitEnabled := false
|
||||||
|
cdromCloudInitFileID := ""
|
||||||
|
|
||||||
if cdromFileID == "" {
|
if cdromFileID == "" {
|
||||||
cdromFileID = "cdrom"
|
cdromFileID = "cdrom"
|
||||||
}
|
}
|
||||||
@ -1347,8 +1360,8 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
|||||||
initializationBlock := initialization[0].(map[string]interface{})
|
initializationBlock := initialization[0].(map[string]interface{})
|
||||||
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
||||||
|
|
||||||
cdromEnabled = true
|
cdromCloudInitEnabled = true
|
||||||
cdromFileID = fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
cdromCloudInitFileID = fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboardLayout := d.Get(mkResourceVirtualEnvironmentVMKeyboardLayout).(string)
|
keyboardLayout := d.Get(mkResourceVirtualEnvironmentVMKeyboardLayout).(string)
|
||||||
@ -1433,6 +1446,11 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
|||||||
proxmox.CustomStorageDevice{
|
proxmox.CustomStorageDevice{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
},
|
},
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: cdromCloudInitEnabled,
|
||||||
|
FileVolume: cdromCloudInitFileID,
|
||||||
|
Media: &ideDevice2Media,
|
||||||
|
},
|
||||||
proxmox.CustomStorageDevice{
|
proxmox.CustomStorageDevice{
|
||||||
Enabled: cdromEnabled,
|
Enabled: cdromEnabled,
|
||||||
FileVolume: cdromFileID,
|
FileVolume: cdromFileID,
|
||||||
@ -2167,34 +2185,33 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compare the IDE devices to the CDROM and cloud-init configurations stored in the state.
|
// Compare the IDE devices to the CDROM and cloud-init configurations stored in the state.
|
||||||
if vmConfig.IDEDevice2 != nil {
|
if vmConfig.IDEDevice3 != nil {
|
||||||
if *vmConfig.IDEDevice2.Media == "cdrom" {
|
|
||||||
if strings.Contains(vmConfig.IDEDevice2.FileVolume, fmt.Sprintf("vm-%d-cloudinit", vmID)) {
|
|
||||||
d.Set(mkResourceVirtualEnvironmentVMCDROM, []interface{}{})
|
|
||||||
} else {
|
|
||||||
d.Set(mkResourceVirtualEnvironmentVMInitialization, []interface{}{})
|
|
||||||
|
|
||||||
cdrom := make([]interface{}, 1)
|
cdrom := make([]interface{}, 1)
|
||||||
cdromBlock := map[string]interface{}{}
|
cdromBlock := map[string]interface{}{}
|
||||||
|
|
||||||
cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled] = true
|
|
||||||
cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID] = vmConfig.IDEDevice2.FileVolume
|
|
||||||
|
|
||||||
cdrom[0] = cdromBlock
|
|
||||||
|
|
||||||
currentCDROM := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{})
|
currentCDROM := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{})
|
||||||
|
|
||||||
if len(clone) == 0 || len(currentCDROM) > 0 {
|
if len(clone) == 0 || len(currentCDROM) > 0 {
|
||||||
|
cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled] = vmConfig.IDEDevice3.Enabled
|
||||||
|
cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID] = vmConfig.IDEDevice3.FileVolume
|
||||||
|
|
||||||
|
isCurrentCDROMFileId := currentCDROM[0].(map[string]interface{})
|
||||||
|
|
||||||
|
if isCurrentCDROMFileId[mkResourceVirtualEnvironmentVMCDROMFileID] == "" {
|
||||||
|
cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID] = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if isCurrentCDROMFileId[mkResourceVirtualEnvironmentVMCDROMEnabled] == false {
|
||||||
|
cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled] = false
|
||||||
|
}
|
||||||
|
|
||||||
|
cdrom[0] = cdromBlock
|
||||||
|
|
||||||
d.Set(mkResourceVirtualEnvironmentVMCDROM, cdrom)
|
d.Set(mkResourceVirtualEnvironmentVMCDROM, cdrom)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
d.Set(mkResourceVirtualEnvironmentVMCDROM, []interface{}{})
|
d.Set(mkResourceVirtualEnvironmentVMCDROM, []interface{}{})
|
||||||
d.Set(mkResourceVirtualEnvironmentVMInitialization, []interface{}{})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
d.Set(mkResourceVirtualEnvironmentVMCDROM, []interface{}{})
|
|
||||||
d.Set(mkResourceVirtualEnvironmentVMInitialization, []interface{}{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare the CPU configuration to the one stored in the state.
|
// Compare the CPU configuration to the one stored in the state.
|
||||||
@ -2943,6 +2960,9 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
|||||||
proxmox.CustomStorageDevice{
|
proxmox.CustomStorageDevice{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
},
|
},
|
||||||
|
proxmox.CustomStorageDevice{
|
||||||
|
Enabled: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3049,13 +3069,17 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
|||||||
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
||||||
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
||||||
|
|
||||||
|
if cdromEnabled == false && cdromFileID == "" {
|
||||||
|
delete = append(delete, "ide3")
|
||||||
|
}
|
||||||
|
|
||||||
if cdromFileID == "" {
|
if cdromFileID == "" {
|
||||||
cdromFileID = "cdrom"
|
cdromFileID = "cdrom"
|
||||||
}
|
}
|
||||||
|
|
||||||
cdromMedia := "cdrom"
|
cdromMedia := "cdrom"
|
||||||
|
|
||||||
updateBody.IDEDevices[2] = proxmox.CustomStorageDevice{
|
updateBody.IDEDevices[3] = proxmox.CustomStorageDevice{
|
||||||
Enabled: cdromEnabled,
|
Enabled: cdromEnabled,
|
||||||
FileVolume: cdromFileID,
|
FileVolume: cdromFileID,
|
||||||
Media: &cdromMedia,
|
Media: &cdromMedia,
|
||||||
|
Loading…
Reference in New Issue
Block a user