diff --git a/internal/provider/resource_repository.go b/internal/provider/resource_repository.go index f2c4e23..c7cfc03 100644 --- a/internal/provider/resource_repository.go +++ b/internal/provider/resource_repository.go @@ -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" ) @@ -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",