0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-29 18:21:10 +00:00
terraform-provider-proxmox/fwprovider/vm/resource_schema.go
Pavel Boldyrev 3119194292
feat(vm): add RNG device support (#1774)
* feat(vm): add RNG device  support

This commit adds support for configuring the Random Number Generator (RNG) device for virtual machines in both the VM resource and datasource. The implementation includes:

- New schema and model for RNG configuration
- Support for setting RNG source, max_bytes, and period
- Updated documentation for RNG configuration
- Test cases for RNG configuration
- Integration with VM creation, update, and read operations

---------

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2025-02-16 23:53:40 -05:00

119 lines
4.5 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 vm
import (
"context"
"regexp"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/bpg/terraform-provider-proxmox/fwprovider/types/stringset"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/cdrom"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/cpu"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/rng"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/vga"
)
// Schema defines the schema for the resource.
func (r *Resource) Schema(
ctx context.Context,
_ resource.SchemaRequest,
resp *resource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Description: "This is an experimental implementation of a Proxmox VM resource using Plugin Framework.",
MarkdownDescription: "This is an experimental implementation of a Proxmox VM resource using Plugin Framework." +
"<br><br>It is a Proof of Concept, highly experimental and **will** change in future. " +
"It does not support all features of the Proxmox API for VMs and **MUST NOT** be used in production.",
Attributes: map[string]schema.Attribute{
"clone": schema.SingleNestedAttribute{
Description: "The cloning configuration.",
Optional: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.RequiresReplace(),
},
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
Description: "The ID of the VM to clone.",
Required: true,
},
"retries": schema.Int64Attribute{
Description: "The number of retries to perform when cloning the VM (default: 3).",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(3),
},
},
},
"cdrom": cdrom.ResourceSchema(),
"cpu": cpu.ResourceSchema(),
"description": schema.StringAttribute{
Description: "The description of the VM.",
Optional: true,
},
"id": schema.Int64Attribute{
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
int64planmodifier.RequiresReplace(),
},
Description: "The unique identifier of the VM in the Proxmox cluster.",
},
"name": schema.StringAttribute{
Description: "The name of the VM.",
MarkdownDescription: "The name of the VM. Doesn't have to be unique.",
Optional: true,
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])$`),
"must be a valid DNS name",
),
},
},
"node_name": schema.StringAttribute{
Description: "The name of the node where the VM is provisioned.",
Required: true,
},
"rng": rng.ResourceSchema(),
"stop_on_destroy": schema.BoolAttribute{
Description: "Set to true to stop (rather than shutdown) the VM on destroy.",
MarkdownDescription: "Set to true to stop (rather than shutdown) the VM on destroy (defaults to `false`).",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"tags": stringset.ResourceAttribute("The tags assigned to the VM.", ""),
"template": schema.BoolAttribute{
Description: "Set to true to create a VM template.",
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.RequiresReplace(),
},
},
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
Create: true,
Read: true,
Update: true,
Delete: true,
}),
"vga": vga.ResourceSchema(),
},
}
}