Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow white space characters in the label of an SSH key #1659

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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