0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-05 13:33:58 +00:00

feat(vm): add initial support for IDE (#1237)

* feat(vm): add initial support for IDE

Very broken, doesn't properly work at the moment, WIP

Signed-off-by: DevMiner <devminer@devminer.xyz>

* add acceptance test for ide disks, fixed few issues

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

* update VM example

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: DevMiner <devminer@devminer.xyz>
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
DevMiner 2024-04-30 02:11:07 +02:00 committed by GitHub
parent 2eb36f4134
commit bd195d6606
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 89 additions and 21 deletions

View File

@ -40,12 +40,12 @@ resource "proxmox_virtual_environment_vm" "example_template" {
version = "v2.0" version = "v2.0"
} }
# disk { disk {
# datastore_id = local.datastore_id datastore_id = local.datastore_id
# file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id file_format = "raw"
# interface = "virtio0" interface = "ide0"
# iothread = true size = 8
# } }
disk { disk {
datastore_id = local.datastore_id datastore_id = local.datastore_id

View File

@ -609,6 +609,54 @@ func TestAccResourceVMDisks(t *testing.T) {
RefreshState: true, RefreshState: true,
}, },
}}, }},
{"ide disks", []resource.TestStep{
{
Config: te.renderConfig(`
resource "proxmox_virtual_environment_vm" "test_disks" {
node_name = "{{.NodeName}}"
started = false
name = "test-disks-ide"
disk {
file_format = "raw"
datastore_id = "local-lvm"
interface = "ide0"
size = 8
}
}`),
Check: testResourceAttributes("proxmox_virtual_environment_vm.test_disks", map[string]string{
"disk.0.interface": "ide0",
"disk.0.path_in_datastore": `vm-\d+-disk-0`,
}),
},
{
Config: te.renderConfig(`
resource "proxmox_virtual_environment_vm" "test_disks" {
node_name = "{{.NodeName}}"
started = false
name = "test-disks-ide"
disk {
file_format = "raw"
datastore_id = "local-lvm"
interface = "ide0"
size = 8
}
disk {
file_format = "raw"
datastore_id = "local-lvm"
interface = "ide1"
size = 8
}
}`),
Check: testResourceAttributes("proxmox_virtual_environment_vm.test_disks", map[string]string{
"disk.#": "2",
}),
},
{
RefreshState: true,
},
}},
{"clone disk with overrides", []resource.TestStep{ {"clone disk with overrides", []resource.TestStep{
{ {
SkipFunc: func() (bool, error) { SkipFunc: func() (bool, error) {

View File

@ -23,6 +23,8 @@ import (
"github.com/bpg/terraform-provider-proxmox/utils" "github.com/bpg/terraform-provider-proxmox/utils"
) )
const supportedDiskInterfaces = "virtio, sata, scsi, ide"
// GetInfo returns the disk information for a VM. // GetInfo returns the disk information for a VM.
func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorageDevices { func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorageDevices {
storageDevices := vms.CustomStorageDevices{} storageDevices := vms.CustomStorageDevices{}
@ -137,6 +139,13 @@ func CreateClone(
} }
diskUpdateBody.SCSIDevices[diskInterface] = configuredDiskInfo diskUpdateBody.SCSIDevices[diskInterface] = configuredDiskInfo
case "ide":
if diskUpdateBody.IDEDevices == nil {
diskUpdateBody.IDEDevices = vms.CustomStorageDevices{}
}
diskUpdateBody.IDEDevices[diskInterface] = configuredDiskInfo
} }
err := vmAPI.UpdateVM(ctx, diskUpdateBody) err := vmAPI.UpdateVM(ctx, diskUpdateBody)
@ -293,7 +302,7 @@ func GetDiskDeviceObjects(
diskDevice.SSD = &ssd diskDevice.SSD = &ssd
} }
if !strings.HasPrefix(diskInterface, "sata") { if !strings.HasPrefix(diskInterface, "sata") && !strings.HasPrefix(diskInterface, "ide") {
diskDevice.IOThread = &ioThread diskDevice.IOThread = &ioThread
} }
@ -341,12 +350,10 @@ func GetDiskDeviceObjects(
} }
baseDiskInterface := DigitPrefix(diskInterface) baseDiskInterface := DigitPrefix(diskInterface)
if !strings.Contains(supportedDiskInterfaces, baseDiskInterface) {
if baseDiskInterface != "virtio" && baseDiskInterface != "scsi" &&
baseDiskInterface != "sata" {
errorMsg := fmt.Sprintf( errorMsg := fmt.Sprintf(
"Defined disk interface not supported. Interface was %s, but only virtio, sata and scsi are supported", "Defined disk interface not supported. Interface was %s, but only %s are supported",
diskInterface, diskInterface, supportedDiskInterfaces,
) )
return diskDeviceObjects, errors.New(errorMsg) return diskDeviceObjects, errors.New(errorMsg)
@ -584,7 +591,7 @@ func Read(
var diags diag.Diagnostics var diags diag.Diagnostics
for di, dd := range diskObjects { for di, dd := range diskObjects {
if dd == nil || dd.FileVolume == "none" || strings.HasPrefix(di, "ide") { if dd == nil || dd.FileVolume == "none" {
continue continue
} }
@ -823,10 +830,13 @@ func Update(
updateBody.SCSIDevices[key] = tmp updateBody.SCSIDevices[key] = tmp
} }
//nolint:revive
case "ide": case "ide":
{ {
// Investigate whether to support IDE mapping. if updateBody.IDEDevices == nil {
updateBody.IDEDevices = vms.CustomStorageDevices{}
}
updateBody.IDEDevices[key] = tmp
} }
default: default:
return false, fmt.Errorf("device prefix %s not supported", prefix) return false, fmt.Errorf("device prefix %s not supported", prefix)

View File

@ -2463,7 +2463,7 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
virtioDeviceObjects := diskDeviceObjects["virtio"] virtioDeviceObjects := diskDeviceObjects["virtio"]
scsiDeviceObjects := diskDeviceObjects["scsi"] scsiDeviceObjects := diskDeviceObjects["scsi"]
// ideDeviceObjects := getOrderedDiskDeviceList(diskDeviceObjects, "ide") ideDeviceObjects := diskDeviceObjects["ide"]
sataDeviceObjects := diskDeviceObjects["sata"] sataDeviceObjects := diskDeviceObjects["sata"]
initializationConfig := vmGetCloudInitConfig(d) initializationConfig := vmGetCloudInitConfig(d)
@ -2576,6 +2576,10 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
bootOrder := d.Get(mkBootOrder).([]interface{}) bootOrder := d.Get(mkBootOrder).([]interface{})
if len(bootOrder) == 0 { if len(bootOrder) == 0 {
if ideDeviceObjects != nil {
bootOrderConverted = append(bootOrderConverted, "ide0")
}
if sataDeviceObjects != nil { if sataDeviceObjects != nil {
bootOrderConverted = append(bootOrderConverted, "sata0") bootOrderConverted = append(bootOrderConverted, "sata0")
} }
@ -2604,17 +2608,19 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
} }
ideDevice2Media := "cdrom" ideDevice2Media := "cdrom"
ideDevices := vms.CustomStorageDevices{ ideDevices := vms.CustomStorageDevices{}
cdromCloudInitInterface: &vms.CustomStorageDevice{
if cdromCloudInitEnabled {
ideDevices[cdromCloudInitInterface] = &vms.CustomStorageDevice{
Enabled: cdromCloudInitEnabled, Enabled: cdromCloudInitEnabled,
FileVolume: cdromCloudInitFileID, FileVolume: cdromCloudInitFileID,
Media: &ideDevice2Media, Media: &ideDevice2Media,
}, }
cdromInterface: &vms.CustomStorageDevice{ ideDevices[cdromInterface] = &vms.CustomStorageDevice{
Enabled: cdromEnabled, Enabled: cdromEnabled,
FileVolume: cdromFileID, FileVolume: cdromFileID,
Media: &ideDevice2Media, Media: &ideDevice2Media,
}, }
} }
if memoryShared > 0 { if memoryShared > 0 {
@ -2672,6 +2678,10 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
VMID: vmID, VMID: vmID,
} }
if ideDeviceObjects != nil {
createBody.IDEDevices = ideDeviceObjects
}
if sataDeviceObjects != nil { if sataDeviceObjects != nil {
createBody.SATADevices = sataDeviceObjects createBody.SATADevices = sataDeviceObjects
} }