Skip to content

Commit c38e811

Browse files
committed
Regex Validation added in user_resource as per present in Vault
1 parent 6487eba commit c38e811

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/vault/auth/userpass/user_resource.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ import (
3535
"github.com/hashicorp/terraform-provider-vault/util"
3636
)
3737

38-
var userRegexp = regexp.MustCompile(`^auth/(.+)/users/(.+)$`)
38+
const userpassUsernamePattern = `\w(?:[\w-.]*\w)?`
39+
40+
var userpassUsernameRegexp = regexp.MustCompile(`^` + userpassUsernamePattern + `$`)
41+
42+
var userRegexp = regexp.MustCompile(`^auth/(.+)/users/(` + userpassUsernamePattern + `)$`)
3943

4044
const bcryptHashLength = 60
4145

@@ -82,6 +86,9 @@ func (r *UserpassAuthUserResource) Schema(_ context.Context, _ resource.SchemaRe
8286
consts.FieldUsername: schema.StringAttribute{
8387
MarkdownDescription: "Username for this Userpass user.",
8488
Required: true,
89+
Validators: []validator.String{
90+
stringvalidator.RegexMatches(userpassUsernameRegexp, "must start and end with a letter, number, or underscore and otherwise contain only letters, numbers, underscores, hyphens, and periods"),
91+
},
8592
PlanModifiers: []planmodifier.String{
8693
stringplanmodifier.RequiresReplace(),
8794
},

0 commit comments

Comments
 (0)