0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-29 18:21:10 +00:00

fix(vm): allow scsi and sata for CD-ROM interface (#1971)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2025-05-21 17:58:55 -04:00 committed by GitHub
parent 9655bd9ec7
commit b1b8d1570f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 12 deletions

View File

@ -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

View File

@ -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(`

View File

@ -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.

View File

@ -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()