0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +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"
}
# disk {
# datastore_id = local.datastore_id
# file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
# interface = "virtio0"
# iothread = true
# }
disk {
datastore_id = local.datastore_id
file_format = "raw"
interface = "ide0"
size = 8
}
disk {
datastore_id = local.datastore_id

View File

@ -609,6 +609,54 @@ func TestAccResourceVMDisks(t *testing.T) {
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{
{
SkipFunc: func() (bool, error) {

View File

@ -23,6 +23,8 @@ import (
"github.com/bpg/terraform-provider-proxmox/utils"
)
const supportedDiskInterfaces = "virtio, sata, scsi, ide"
// GetInfo returns the disk information for a VM.
func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorageDevices {
storageDevices := vms.CustomStorageDevices{}
@ -137,6 +139,13 @@ func CreateClone(
}
diskUpdateBody.SCSIDevices[diskInterface] = configuredDiskInfo
case "ide":
if diskUpdateBody.IDEDevices == nil {
diskUpdateBody.IDEDevices = vms.CustomStorageDevices{}
}
diskUpdateBody.IDEDevices[diskInterface] = configuredDiskInfo
}
err := vmAPI.UpdateVM(ctx, diskUpdateBody)
@ -293,7 +302,7 @@ func GetDiskDeviceObjects(
diskDevice.SSD = &ssd
}
if !strings.HasPrefix(diskInterface, "sata") {
if !strings.HasPrefix(diskInterface, "sata") && !strings.HasPrefix(diskInterface, "ide") {
diskDevice.IOThread = &ioThread
}
@ -341,12 +350,10 @@ func GetDiskDeviceObjects(
}
baseDiskInterface := DigitPrefix(diskInterface)
if baseDiskInterface != "virtio" && baseDiskInterface != "scsi" &&
baseDiskInterface != "sata" {
if !strings.Contains(supportedDiskInterfaces, baseDiskInterface) {
errorMsg := fmt.Sprintf(
"Defined disk interface not supported. Interface was %s, but only virtio, sata and scsi are supported",
diskInterface,
"Defined disk interface not supported. Interface was %s, but only %s are supported",
diskInterface, supportedDiskInterfaces,
)
return diskDeviceObjects, errors.New(errorMsg)
@ -584,7 +591,7 @@ func Read(
var diags diag.Diagnostics
for di, dd := range diskObjects {
if dd == nil || dd.FileVolume == "none" || strings.HasPrefix(di, "ide") {
if dd == nil || dd.FileVolume == "none" {
continue
}
@ -823,10 +830,13 @@ func Update(
updateBody.SCSIDevices[key] = tmp
}
//nolint:revive
case "ide":
{
// Investigate whether to support IDE mapping.
if updateBody.IDEDevices == nil {
updateBody.IDEDevices = vms.CustomStorageDevices{}
}
updateBody.IDEDevices[key] = tmp
}
default:
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"]
scsiDeviceObjects := diskDeviceObjects["scsi"]
// ideDeviceObjects := getOrderedDiskDeviceList(diskDeviceObjects, "ide")
ideDeviceObjects := diskDeviceObjects["ide"]
sataDeviceObjects := diskDeviceObjects["sata"]
initializationConfig := vmGetCloudInitConfig(d)
@ -2576,6 +2576,10 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
bootOrder := d.Get(mkBootOrder).([]interface{})
if len(bootOrder) == 0 {
if ideDeviceObjects != nil {
bootOrderConverted = append(bootOrderConverted, "ide0")
}
if sataDeviceObjects != nil {
bootOrderConverted = append(bootOrderConverted, "sata0")
}
@ -2604,17 +2608,19 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
}
ideDevice2Media := "cdrom"
ideDevices := vms.CustomStorageDevices{
cdromCloudInitInterface: &vms.CustomStorageDevice{
ideDevices := vms.CustomStorageDevices{}
if cdromCloudInitEnabled {
ideDevices[cdromCloudInitInterface] = &vms.CustomStorageDevice{
Enabled: cdromCloudInitEnabled,
FileVolume: cdromCloudInitFileID,
Media: &ideDevice2Media,
},
cdromInterface: &vms.CustomStorageDevice{
}
ideDevices[cdromInterface] = &vms.CustomStorageDevice{
Enabled: cdromEnabled,
FileVolume: cdromFileID,
Media: &ideDevice2Media,
},
}
}
if memoryShared > 0 {
@ -2672,6 +2678,10 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
VMID: vmID,
}
if ideDeviceObjects != nil {
createBody.IDEDevices = ideDeviceObjects
}
if sataDeviceObjects != nil {
createBody.SATADevices = sataDeviceObjects
}