Skip to content

Commit

Permalink
Allow white space characters in the label of a SSH key
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Nov 13, 2024
1 parent ccf6f1f commit 7af029d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 2 additions & 9 deletions linode/helper/regex.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package helper

import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func StringToRegex(pattern string) (regExp *regexp.Regexp) {
regExp, err := regexp.Compile(pattern)
if err != nil {
fmt.Println("Error compiling regex:", err)
return
}

return regExp
func StringToRegex(pattern string) *regexp.Regexp {
return regexp.MustCompile(pattern)
}

func RegexMatches(pattern string, errorMessage string) validator.String {
Expand Down
2 changes: 1 addition & 1 deletion linode/sshkey/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
SSHKeyLabelRegex = "^[a-zA-Z0-9_-]*$"
SSHKeyLabelRegex = "^[a-zA-Z0-9_\\-\\s]*$"
SSHKeyLabelErrorMessage = "Labels may only contain letters, number, dashes, and underscores."
)

Expand Down
27 changes: 27 additions & 0 deletions linode/sshkey/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@ func TestAccResourceSSHKey_basic(t *testing.T) {
})
}

func TestAccResourceSSHKey_space_in_label(t *testing.T) {
t.Parallel()

resName := "linode_sshkey.foobar"
sshkeyName := acctest.RandomWithPrefix("tf_test") + " "

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: checkSSHKeyDestroy,
Steps: []resource.TestStep{
{
Config: tmpl.Basic(t, sshkeyName, acceptance.PublicKeyMaterial),
Check: resource.ComposeTestCheckFunc(
checkSSHKeyExists,
resource.TestCheckResourceAttr(resName, "label", sshkeyName),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccResourceSSHKey_update(t *testing.T) {
t.Parallel()
resName := "linode_sshkey.foobar"
Expand Down

0 comments on commit 7af029d

Please sign in to comment.