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"`
|
||||
IDEDevice1 *CustomStorageDevice `json:"ide1,omitempty"`
|
||||
IDEDevice2 *CustomStorageDevice `json:"ide2,omitempty"`
|
||||
IDEDevice3 *CustomStorageDevice `json:"ide3,omitempty"`
|
||||
IPConfig0 *CustomCloudInitIPConfig `json:"ipconfig0,omitempty"`
|
||||
IPConfig1 *CustomCloudInitIPConfig `json:"ipconfig1,omitempty"`
|
||||
IPConfig2 *CustomCloudInitIPConfig `json:"ipconfig2,omitempty"`
|
||||
|
@ -1061,6 +1061,8 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
||||
AudioDevices: audioDevices,
|
||||
}
|
||||
|
||||
ideDevices := proxmox.CustomStorageDevices{}
|
||||
|
||||
delete := []string{}
|
||||
|
||||
if acpi != dvResourceVirtualEnvironmentVMACPI {
|
||||
@ -1085,6 +1087,23 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
||||
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 {
|
||||
cdromBlock := cdrom[0].(map[string]interface{})
|
||||
|
||||
@ -1097,19 +1116,13 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
||||
|
||||
cdromMedia := "cdrom"
|
||||
|
||||
updateBody.IDEDevices = proxmox.CustomStorageDevices{
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
cdromDevice := proxmox.CustomStorageDevice{
|
||||
Enabled: cdromEnabled,
|
||||
FileVolume: cdromFileID,
|
||||
Media: &cdromMedia,
|
||||
},
|
||||
}
|
||||
|
||||
ideDevices[3] = cdromDevice
|
||||
}
|
||||
|
||||
if len(cpu) > 0 {
|
||||
@ -1151,24 +1164,17 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
||||
initializationBlock := initialization[0].(map[string]interface{})
|
||||
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
||||
|
||||
cdromEnabled := true
|
||||
cdromFileID := fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||
cdromMedia := "cdrom"
|
||||
cdromCloudInitEnabled := true
|
||||
cdromCloudInitFileID := fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||
cdromCloudInitMedia := "cdrom"
|
||||
|
||||
updateBody.IDEDevices = proxmox.CustomStorageDevices{
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: cdromEnabled,
|
||||
FileVolume: cdromFileID,
|
||||
Media: &cdromMedia,
|
||||
},
|
||||
cdromCloudInitDevice := proxmox.CustomStorageDevice{
|
||||
Enabled: cdromCloudInitEnabled,
|
||||
FileVolume: cdromCloudInitFileID,
|
||||
Media: &cdromCloudInitMedia,
|
||||
}
|
||||
|
||||
ideDevices[2] = cdromCloudInitDevice
|
||||
initializationConfig, err := resourceVirtualEnvironmentVMGetCloudInitConfig(d, m)
|
||||
|
||||
if err != nil {
|
||||
@ -1178,6 +1184,10 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
|
||||
updateBody.CloudInitConfig = initializationConfig
|
||||
}
|
||||
|
||||
if len(cdrom) > 0 || len(initialization) > 0 {
|
||||
updateBody.IDEDevices = ideDevices
|
||||
}
|
||||
|
||||
if keyboardLayout != dvResourceVirtualEnvironmentVMKeyboardLayout {
|
||||
updateBody.KeyboardLayout = &keyboardLayout
|
||||
}
|
||||
@ -1311,6 +1321,9 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
||||
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
||||
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
||||
|
||||
cdromCloudInitEnabled := false
|
||||
cdromCloudInitFileID := ""
|
||||
|
||||
if cdromFileID == "" {
|
||||
cdromFileID = "cdrom"
|
||||
}
|
||||
@ -1347,8 +1360,8 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
||||
initializationBlock := initialization[0].(map[string]interface{})
|
||||
initializationDatastoreID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string)
|
||||
|
||||
cdromEnabled = true
|
||||
cdromFileID = fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||
cdromCloudInitEnabled = true
|
||||
cdromCloudInitFileID = fmt.Sprintf("%s:cloudinit", initializationDatastoreID)
|
||||
}
|
||||
|
||||
keyboardLayout := d.Get(mkResourceVirtualEnvironmentVMKeyboardLayout).(string)
|
||||
@ -1433,6 +1446,11 @@ func resourceVirtualEnvironmentVMCreateCustom(d *schema.ResourceData, m interfac
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: cdromCloudInitEnabled,
|
||||
FileVolume: cdromCloudInitFileID,
|
||||
Media: &ideDevice2Media,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: cdromEnabled,
|
||||
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.
|
||||
if vmConfig.IDEDevice2 != 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{}{})
|
||||
if vmConfig.IDEDevice3 != nil {
|
||||
|
||||
cdrom := make([]interface{}, 1)
|
||||
cdromBlock := map[string]interface{}{}
|
||||
|
||||
cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled] = true
|
||||
cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID] = vmConfig.IDEDevice2.FileVolume
|
||||
|
||||
cdrom[0] = cdromBlock
|
||||
|
||||
currentCDROM := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
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.
|
||||
@ -2943,6 +2960,9 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
proxmox.CustomStorageDevice{
|
||||
Enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -3049,13 +3069,17 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
||||
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
||||
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
||||
|
||||
if cdromEnabled == false && cdromFileID == "" {
|
||||
delete = append(delete, "ide3")
|
||||
}
|
||||
|
||||
if cdromFileID == "" {
|
||||
cdromFileID = "cdrom"
|
||||
}
|
||||
|
||||
cdromMedia := "cdrom"
|
||||
|
||||
updateBody.IDEDevices[2] = proxmox.CustomStorageDevice{
|
||||
updateBody.IDEDevices[3] = proxmox.CustomStorageDevice{
|
||||
Enabled: cdromEnabled,
|
||||
FileVolume: cdromFileID,
|
||||
Media: &cdromMedia,
|
||||
|
Loading…
Reference in New Issue
Block a user