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/rng/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

71 lines
2.8 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 rng
import (
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"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/hashicorp/terraform-plugin-framework/types/basetypes"
)
// ResourceSchema defines the schema for the RNG resource.
func ResourceSchema() schema.Attribute {
return schema.SingleNestedAttribute{
CustomType: basetypes.ObjectType{
AttrTypes: attributeTypes(),
},
Description: "The RNG (Random Number Generator) configuration. Can only be set by `root@pam.`",
MarkdownDescription: "Configure the RNG (Random Number Generator) device. The RNG device provides entropy " +
"to guests to ensure good quality random numbers for guest applications that require them. " +
"Can only be set by `root@pam.`" +
"See the [Proxmox documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_virtual_machines_settings) " +
"for more information.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
Attributes: map[string]schema.Attribute{
"source": schema.StringAttribute{
Description: "The entropy source for the RNG device.",
MarkdownDescription: "The file on the host to gather entropy from. " +
"In most cases, `/dev/urandom` should be preferred over `/dev/random` " +
"to avoid entropy-starvation issues on the host.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
"max_bytes": schema.Int64Attribute{
Description: "Maximum bytes of entropy allowed to get injected into the guest every period.",
MarkdownDescription: "Maximum bytes of entropy allowed to get injected into the guest every period. " +
"Use 0 to disable limiting (potentially dangerous).",
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.AtLeast(0),
},
},
"period": schema.Int64Attribute{
Description: "Period in milliseconds to limit entropy injection to the guest.",
MarkdownDescription: "Period in milliseconds to limit entropy injection to the guest. " +
"Use 0 to disable limiting (potentially dangerous).",
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.AtLeast(0),
},
},
},
}
}