Skip to content

Commit

Permalink
Merge pull request #8 from crusoecloud/fix-ssh-keys
Browse files Browse the repository at this point in the history
Support vars in validators
  • Loading branch information
agutierrez8 authored Aug 24, 2023
2 parents d35914c + 778229c commit 95a2972
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/validators/regex_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (v RegexValidator) MarkdownDescription(ctx context.Context) string {

//nolint:gocritic // Implements Terraform defined interface
func (v RegexValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
// skip validation if the value is still unknown, which is the case for vars before evaluation
if req.ConfigValue.IsUnknown() {
return
}

r := regexp.MustCompile(v.RegexPattern)

if !r.MatchString(req.ConfigValue.ValueString()) {
Expand Down
5 changes: 5 additions & 0 deletions internal/validators/ssh_key_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (v SSHKeyValidator) MarkdownDescription(ctx context.Context) string {

//nolint:gocritic // Implements Terraform defined interface
func (v SSHKeyValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
// skip validation if the value is still unknown, which is the case for vars before evaluation
if req.ConfigValue.IsUnknown() {
return
}

input := req.ConfigValue.ValueString()

_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(input))
Expand Down

0 comments on commit 95a2972

Please sign in to comment.