Skip to content

Commit

Permalink
fix: added space validations
Browse files Browse the repository at this point in the history
Signed-off-by: Paul <[email protected]>
  • Loading branch information
Pauti committed Jun 21, 2024
1 parent 4f3c063 commit 681e6ad
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/provider/space_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ package provider
import (
"context"
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
mondoov1 "go.mondoo.com/mondoo-go"
Expand Down Expand Up @@ -56,6 +59,12 @@ func (r *SpaceResource) Schema(ctx context.Context, req resource.SchemaRequest,
"name": schema.StringAttribute{
MarkdownDescription: "Name of the space.",
Optional: true,
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^([a-zA-Z \-'_]|\d){2,30}$`),
"must contain 2 to 30 characters, where each character can be a letter (uppercase or lowercase), a space, a dash, an underscore, or a digit",
),
},
},
"id": schema.StringAttribute{
MarkdownDescription: "Id of the space. Must be globally unique.",
Expand All @@ -64,6 +73,12 @@ func (r *SpaceResource) Schema(ctx context.Context, req resource.SchemaRequest,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-z]([\d-_]|[a-z]){6,35}[a-z\d]$`),
"must contain 6 to 35 digits, dashes, underscores, or lowercase letters, and ending with either a lowercase letter or a digit",
),
},
},
"mrn": schema.StringAttribute{
MarkdownDescription: "Mrn of the space.",
Expand All @@ -75,6 +90,12 @@ func (r *SpaceResource) Schema(ctx context.Context, req resource.SchemaRequest,
"org_id": schema.StringAttribute{
MarkdownDescription: "Id of the organization.",
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-z]([\d-_]|[a-z]){6,35}[a-z\d]$`),
"must contain 6 to 35 digits, dashes, underscores, or lowercase letters, and ending with either a lowercase letter or a digit",
),
},
},
},
}
Expand Down

0 comments on commit 681e6ad

Please sign in to comment.