mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
feat(vm2): add initial support for `cdrom` This is a breaking change comparing to v1 - switching the cdrom schema from a nested block to a nested attribute map. Improvements comparing to v1: - support for `ide`, `sata`, `scsi` interfaces - support for multiple cdroms Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package cdrom
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator"
|
|
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
|
|
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
|
|
|
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"
|
|
)
|
|
|
|
// ResourceSchema defines the schema for the CD-ROM resource.
|
|
func ResourceSchema() schema.Attribute {
|
|
return schema.MapNestedAttribute{
|
|
Description: "The CD-ROM configuration",
|
|
MarkdownDescription: "The CD-ROM configuration. The key is the interface of the CD-ROM, " +
|
|
"could be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface.",
|
|
Optional: true,
|
|
Computed: true,
|
|
Validators: []validator.Map{
|
|
mapvalidator.KeysAre(
|
|
stringvalidator.RegexMatches(
|
|
regexp.MustCompile(`^(ide[0-3]|sata[0-5]|scsi([0-9]|1[0-3]))$`),
|
|
"one of `ide[0-3]`, `sata[0-5]`, `scsi[0-13]`",
|
|
),
|
|
),
|
|
},
|
|
NestedObject: schema.NestedAttributeObject{
|
|
Attributes: map[string]schema.Attribute{
|
|
"file_id": schema.StringAttribute{
|
|
Description: "The file ID of the CD-ROM",
|
|
MarkdownDescription: "The file ID of the CD-ROM, or `cdrom|none`." +
|
|
" Defaults to `none` to leave the CD-ROM empty. Use `cdrom` to connect to the physical drive.",
|
|
Optional: true,
|
|
Computed: true,
|
|
Default: stringdefault.StaticString("cdrom"),
|
|
Validators: []validator.String{
|
|
stringvalidator.Any(
|
|
stringvalidator.OneOf("cdrom", "none"),
|
|
validators.FileID(),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|