diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index 564ea4e8..12685ee7 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -107,6 +107,7 @@ const ( dvResourceVirtualEnvironmentVMVGAMemory = 16 dvResourceVirtualEnvironmentVMVGAType = "std" dvResourceVirtualEnvironmentVMVMID = -1 + dvResourceVirtualEnvironmentVMSCSIHardware = "virtio-scsi-pci" maxResourceVirtualEnvironmentVMAudioDevices = 1 maxResourceVirtualEnvironmentVMNetworkDevices = 8 @@ -226,6 +227,7 @@ const ( mkResourceVirtualEnvironmentVMVGAMemory = "memory" mkResourceVirtualEnvironmentVMVGAType = "type" mkResourceVirtualEnvironmentVMVMID = "vm_id" + mkResourceVirtualEnvironmentVMSCSIHardware = "scsi_hardware" ) func resourceVirtualEnvironmentVM() *schema.Resource { @@ -1194,6 +1196,13 @@ func resourceVirtualEnvironmentVM() *schema.Resource { Default: dvResourceVirtualEnvironmentVMVMID, ValidateDiagFunc: getVMIDValidator(), }, + mkResourceVirtualEnvironmentVMSCSIHardware: { + Type: schema.TypeString, + Description: "The SCSI hardware type", + Optional: true, + Default: dvResourceVirtualEnvironmentVMSCSIHardware, + ValidateDiagFunc: getSCSIHardwareValidator(), + }, }, CreateContext: resourceVirtualEnvironmentVMCreate, ReadContext: resourceVirtualEnvironmentVMRead, @@ -1393,6 +1402,7 @@ func resourceVirtualEnvironmentVMCreateClone( bios := d.Get(mkResourceVirtualEnvironmentVMBIOS).(string) kvmArguments := d.Get(mkResourceVirtualEnvironmentVMKVMArguments).(string) + scsiHardware := d.Get(mkResourceVirtualEnvironmentVMSCSIHardware).(string) cdrom := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{}) cpu := d.Get(mkResourceVirtualEnvironmentVMCPU).([]interface{}) initialization := d.Get(mkResourceVirtualEnvironmentVMInitialization).([]interface{}) @@ -1444,6 +1454,10 @@ func resourceVirtualEnvironmentVMCreateClone( updateBody.BIOS = &bios } + if scsiHardware != dvResourceVirtualEnvironmentVMSCSIHardware { + updateBody.SCSIHardware = &scsiHardware + } + if len(cdrom) > 0 || len(initialization) > 0 { ideDevices = proxmox.CustomStorageDevices{ "ide0": proxmox.CustomStorageDevice{ @@ -1951,7 +1965,7 @@ func resourceVirtualEnvironmentVMCreateCustom( } } - scsiHardware := "virtio-scsi-pci" + scsiHardware := d.Get(mkResourceVirtualEnvironmentVMSCSIHardware).(string) createBody := &proxmox.VirtualEnvironmentVMCreateRequestBody{ ACPI: &acpi, @@ -3647,6 +3661,16 @@ func resourceVirtualEnvironmentVMReadCustom( diags = append(diags, diag.FromErr(err)...) } + // Compare SCSI hardware type + scsiHardware := d.Get(mkResourceVirtualEnvironmentVMSCSIHardware).(string) + + if len(clone) == 0 || scsiHardware != dvResourceVirtualEnvironmentVMSCSIHardware { + if vmConfig.SCSIHardware != nil { + err := d.Set(mkResourceVirtualEnvironmentVMSCSIHardware, *vmConfig.SCSIHardware) + diags = append(diags, diag.FromErr(err)...) + } + } + diags = append( diags, resourceVirtualEnvironmentVMReadNetworkValues(ctx, d, m, vmID, vmConfig)...) @@ -4334,6 +4358,14 @@ func resourceVirtualEnvironmentVMUpdate( rebootRequired = true } + // Prepare the new SCSI hardware type + if d.HasChange(mkResourceVirtualEnvironmentVMSCSIHardware) { + scsiHardware := d.Get(mkResourceVirtualEnvironmentVMSCSIHardware).(string) + updateBody.SCSIHardware = &scsiHardware + + rebootRequired = true + } + // Update the configuration now that everything has been prepared. updateBody.Delete = del diff --git a/proxmoxtf/resource_virtual_environment_vm_test.go b/proxmoxtf/resource_virtual_environment_vm_test.go index 871f739e..d87189c4 100644 --- a/proxmoxtf/resource_virtual_environment_vm_test.go +++ b/proxmoxtf/resource_virtual_environment_vm_test.go @@ -52,6 +52,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) { mkResourceVirtualEnvironmentVMTabletDevice, mkResourceVirtualEnvironmentVMTemplate, mkResourceVirtualEnvironmentVMVMID, + mkResourceVirtualEnvironmentVMSCSIHardware, }) testComputedAttributes(t, s, []string{ @@ -89,6 +90,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) { mkResourceVirtualEnvironmentVMTabletDevice: schema.TypeBool, mkResourceVirtualEnvironmentVMTemplate: schema.TypeBool, mkResourceVirtualEnvironmentVMVMID: schema.TypeInt, + mkResourceVirtualEnvironmentVMSCSIHardware: schema.TypeString, }) agentSchema := testNestedSchemaExistence(t, s, mkResourceVirtualEnvironmentVMAgent) diff --git a/proxmoxtf/utils.go b/proxmoxtf/utils.go index bf8f9298..6d1561d9 100644 --- a/proxmoxtf/utils.go +++ b/proxmoxtf/utils.go @@ -338,6 +338,17 @@ func getVGATypeValidator() schema.SchemaValidateDiagFunc { }, false)) } +func getSCSIHardwareValidator() schema.SchemaValidateDiagFunc { + return validation.ToDiagFunc(validation.StringInSlice([]string{ + "lsi", + "lsi53c810", + "virtio-scsi-pci", + "virtio-scsi-single", + "megasas", + "pvscsi", + }, false)) +} + //nolint:unused func getVLANIDsValidator() schema.SchemaValidateDiagFunc { return validation.ToDiagFunc(func(i interface{}, k string) (ws []string, es []error) {