Skip to content

Commit

Permalink
add validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Nam authored and YakDriver committed Jan 8, 2024
1 parent d104c50 commit fd4b24c
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions internal/service/lexv2models/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (
"context"
"errors"
"fmt"
"regexp"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lexmodelsv2"
awstypes "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/types"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"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/planmodifier"
Expand Down Expand Up @@ -182,7 +185,12 @@ func (r *resourceIntent) Schema(ctx context.Context, req resource.SchemaRequest,
Attributes: map[string]schema.Attribute{
"map_block_key": schema.StringAttribute{
Required: true,
// pattern: ^([0-9a-zA-Z][_-]?){1,100}$
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(` ^([0-9a-zA-Z][_-]?){1,100}$`),
"alphanumeric characters and hyphens (-) and underscores (_) at the end and must be between 1 and 100 characters in length",
),
},
},
"shape": schema.StringAttribute{
Optional: true,
Expand All @@ -199,7 +207,9 @@ func (r *resourceIntent) Schema(ctx context.Context, req resource.SchemaRequest,
Attributes: map[string]schema.Attribute{
"interpreted_value": schema.StringAttribute{
Optional: true,
// min length: 1
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
},
},
Expand Down Expand Up @@ -413,9 +423,9 @@ func (r *resourceIntent) Schema(ctx context.Context, req resource.SchemaRequest,
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"start_timeout_ms": schema.Int64Attribute{
Required: true,
Required: true,
Validators: []validator.Int64{
// at least 1
int64validator.AtLeast(1),
},
},
},
Expand All @@ -428,15 +438,15 @@ func (r *resourceIntent) Schema(ctx context.Context, req resource.SchemaRequest,
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"end_timeout_ms": schema.Int64Attribute{
Required: true,
Required: true,
Validators: []validator.Int64{
// at least 1
int64validator.AtLeast(1),
},
},
"max_length_ms": schema.Int64Attribute{
Required: true,
Required: true,
Validators: []validator.Int64{
// at least 1
int64validator.AtLeast(1),
},
},
},
Expand All @@ -451,22 +461,32 @@ func (r *resourceIntent) Schema(ctx context.Context, req resource.SchemaRequest,
Attributes: map[string]schema.Attribute{
"deletion_character": schema.StringAttribute{
Required: true,
// pattern: ^[A-D0-9#*]{1}$
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[A-D0-9#*]{1}$`),
"alphanumeric characters",
),
},
},
"end_character": schema.StringAttribute{
Required: true,
// pattern: ^[A-D0-9#*]{1}$
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[A-D0-9#*]{1}$`),
"alphanumeric characters",
),
},
},
"end_timeout_ms": schema.Int64Attribute{
Required: true,
Required: true,
Validators: []validator.Int64{
// at least 1
int64validator.AtLeast(1),
},
},
"max_length": schema.Int64Attribute{
Required: true,
Required: true,
Validators: []validator.Int64{
//validators.Int64Between(1, 1024),
int64validator.Between(1, 1024),
},
},
},
Expand Down

0 comments on commit fd4b24c

Please sign in to comment.