Skip to content

Commit

Permalink
Merge pull request #20 from docker/bug-fix-11
Browse files Browse the repository at this point in the history
Setup validations for resource
  • Loading branch information
ryanhristovski authored Aug 21, 2024
2 parents 2e7e7ad + a3491c0 commit 9c90292
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/provider/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import (
"context"
"fmt"
"log"
"regexp"
"strings"

"github.com/docker/terraform-provider-docker/internal/pkg/hubclient"
"github.com/docker/terraform-provider-docker/internal/pkg/repositoryutils"
"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/int64planmodifier"
"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"
)

Expand Down Expand Up @@ -177,6 +180,12 @@ func (r *RepositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-z0-9]+(?:[._-][a-z0-9]+)*$`),
"Name must only contain alphanumeric characters, '.', or '-', and must start and end with an alphanumeric character",
),
},
},
"description": schema.StringAttribute{
MarkdownDescription: "Repository description",
Expand Down

0 comments on commit 9c90292

Please sign in to comment.