diff --git a/example/resource_virtual_environment_vm.tf b/example/resource_virtual_environment_vm.tf index 991f5865..823db9ea 100644 --- a/example/resource_virtual_environment_vm.tf +++ b/example/resource_virtual_environment_vm.tf @@ -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 diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index b377bfd0..2f25192e 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -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) { diff --git a/proxmoxtf/resource/vm/disk/disk.go b/proxmoxtf/resource/vm/disk/disk.go index b5e91534..6fb3e13d 100644 --- a/proxmoxtf/resource/vm/disk/disk.go +++ b/proxmoxtf/resource/vm/disk/disk.go @@ -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) diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 48823408..18b0f1df 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -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 }