diff --git a/docs/resources/virtual_environment_vm.md b/docs/resources/virtual_environment_vm.md index ea479abe..beec0b21 100755 --- a/docs/resources/virtual_environment_vm.md +++ b/docs/resources/virtual_environment_vm.md @@ -168,9 +168,9 @@ output "ubuntu_vm_public_key" { Set `file_id` to `none` to leave the CD-ROM drive empty. - `file_id` - (Optional) A file ID for an ISO file (defaults to `cdrom` as in the physical drive). Use `none` to leave the CD-ROM drive empty. - - `interface` - (Optional) A hardware interface to connect CD-ROM drive to, - must be `ideN` (defaults to `ide3`). Note that `q35` machine type only - supports `ide0` and `ide2`. + - `interface` - (Optional) A hardware interface to connect CD-ROM drive to (defaults to `ide3`). + "Must be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. " + + "Note that `q35` machine type only supports `ide0` and `ide2` of IDE interfaces. - `clone` - (Optional) The cloning configuration. - `datastore_id` - (Optional) The identifier for the target datastore. - `node_name` - (Optional) The name of the source node (leave blank, if diff --git a/fwprovider/test/resource_vm_cdrom_test.go b/fwprovider/test/resource_vm_cdrom_test.go index aa4e3884..9c8b5f76 100644 --- a/fwprovider/test/resource_vm_cdrom_test.go +++ b/fwprovider/test/resource_vm_cdrom_test.go @@ -51,6 +51,46 @@ func TestAccResourceVMCDROM(t *testing.T) { RefreshState: true, }, }}, + {"sata cdrom", []resource.TestStep{ + { + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_vm" "test_cdrom" { + node_name = "{{.NodeName}}" + started = false + name = "test-cdrom" + cdrom { + file_id = "none" + interface = "sata3" + } + }`), + Check: ResourceAttributes("proxmox_virtual_environment_vm.test_cdrom", map[string]string{ + "cdrom.0.interface": "sata3", + }), + }, + { + RefreshState: true, + }, + }}, + {"scsi cdrom", []resource.TestStep{ + { + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_vm" "test_cdrom" { + node_name = "{{.NodeName}}" + started = false + name = "test-cdrom" + cdrom { + file_id = "none" + interface = "scsi5" + } + }`), + Check: ResourceAttributes("proxmox_virtual_environment_vm.test_cdrom", map[string]string{ + "cdrom.0.interface": "scsi5", + }), + }, + { + RefreshState: true, + }, + }}, {"enable cdrom", []resource.TestStep{ { Config: te.RenderConfig(` diff --git a/proxmoxtf/resource/vm/validators.go b/proxmoxtf/resource/vm/validators.go index f19648a0..f2ab1ad3 100755 --- a/proxmoxtf/resource/vm/validators.go +++ b/proxmoxtf/resource/vm/validators.go @@ -263,14 +263,12 @@ func SCSIHardwareValidator() schema.SchemaValidateDiagFunc { }, false)) } -// IDEInterfaceValidator is a schema validation function for IDE interfaces. -func IDEInterfaceValidator() schema.SchemaValidateDiagFunc { - return validation.ToDiagFunc(validation.StringInSlice([]string{ - "ide0", - "ide1", - "ide2", - "ide3", - }, false)) +// CDROMInterfaceValidator is a schema validation function for IDE interfaces. +func CDROMInterfaceValidator() schema.SchemaValidateDiagFunc { + return validation.ToDiagFunc(validation.StringMatch( + regexp.MustCompile(`^(ide[0-3]|sata[0-5]|scsi([0-9]|1[0-3]))$`), + "must be one of `ide[0-3]`, `sata[0-5]`, `scsi[0-13]`", + )) } // VirtiofsCacheValidator is a schema validation function for virtiofs cache configs. diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index f0cc8f09..93257ebd 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -531,7 +531,7 @@ func VM() *schema.Resource { Description: "The CDROM interface", Optional: true, Default: dvCDROMInterface, - ValidateDiagFunc: IDEInterfaceValidator(), + ValidateDiagFunc: CDROMInterfaceValidator(), }, }, }, @@ -6003,6 +6003,9 @@ func vmDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D timeout = shutdownTimeout } + // reset the default timeout for the delete operation + ctx = context.WithoutCancel(ctx) + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second) defer cancel()