mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 11:02:59 +00:00
feat(vm): Add scsi_hardware field (#282)
This commit is contained in:
parent
d8c1fb3573
commit
f0f31eee47
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user