Skip to content

Commit

Permalink
Adjust random_bytes to latest sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
Socolin committed Feb 14, 2023
1 parent 0839bdf commit 0f82f05
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions internal/provider/resource_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"encoding/hex"
"fmt"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/terraform-providers/terraform-provider-random/internal/diagnostics"
mapplanmodifiers "github.com/terraform-providers/terraform-provider-random/internal/planmodifiers/map"
)

var (
Expand All @@ -30,8 +33,8 @@ func (r *bytesResource) Metadata(_ context.Context, req resource.MetadataRequest
resp.TypeName = req.ProviderTypeName + "_bytes"
}

func (r *bytesResource) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) {
return bytesSchemaV0(), nil
func (r *bytesResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = bytesSchemaV0()
}

func (r *bytesResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down Expand Up @@ -119,49 +122,48 @@ type bytesModelV0 struct {
ResultHex types.String `tfsdk:"result_hex"`
}

func bytesSchemaV0() tfsdk.Schema {
return tfsdk.Schema{
func bytesSchemaV0() schema.Schema {
return schema.Schema{
Version: 0,
Description: "The resource `random_bytes` generates random bytes that are intended to be " +
"used as secret or keys.",
Attributes: map[string]tfsdk.Attribute{
"keepers": {
Attributes: map[string]schema.Attribute{
"keepers": schema.MapAttribute{
Description: "Arbitrary map of values that, when changed, will trigger recreation of " +
"resource. See [the main provider documentation](../index.html) for more information.",
Type: types.MapType{
ElementType: types.MapType{
ElemType: types.StringType,
},
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
resource.RequiresReplace(),
PlanModifiers: []planmodifier.Map{
mapplanmodifiers.RequiresReplaceIfValuesNotNull(),
},
},
"length": {
"length": schema.Int64Attribute{
Description: "The number of bytes requested. The minimum value for length is 1.",
Type: types.Int64Type,
Required: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
resource.RequiresReplace(),
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
Validators: []tfsdk.AttributeValidator{
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
"result_base64": {
"result_base64": schema.MapAttribute{
Description: "The generated bytes presented in base64 string format.",
Type: types.StringType,
ElementType: types.StringType,
Computed: true,
Sensitive: true,
},
"result_hex": {
"result_hex": schema.MapAttribute{
Description: "The generated bytes presented in hex string format.",
Type: types.StringType,
ElementType: types.StringType,
Computed: true,
Sensitive: true,
},
"id": {
"id": schema.MapAttribute{
Description: "A static value used internally by Terraform, this should not be referenced in configurations.",
Type: types.StringType,
ElementType: types.StringType,
Computed: true,
},
},
Expand Down

0 comments on commit 0f82f05

Please sign in to comment.