Skip to content
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
15 changes: 10 additions & 5 deletions aws/resource_aws_transfer_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,24 @@ func TestAccAWSTransferUser_UserName_Validation(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccAWSTransferUserName_validation("!@#$%^"),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 32 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(2)),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 32 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(33)),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 32 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
Config: testAccAWSTransferUserName_validation(acctest.RandString(33)),
ExpectNonEmptyPlan: true,
PlanOnly: true,
},
{
Config: testAccAWSTransferUserName_validation(acctest.RandString(101)),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
},
{
Config: testAccAWSTransferUserName_validation("-abcdef"),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 32 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
ExpectError: regexp.MustCompile(`Invalid "user_name": must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, "user_name" cannot begin with a hyphen`),
},
{
Config: testAccAWSTransferUserName_validation("valid_username"),
Expand Down
4 changes: 2 additions & 2 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func validateTransferServerID(v interface{}, k string) (ws []string, errors []er
func validateTransferUserName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
// https://docs.aws.amazon.com/transfer/latest/userguide/API_CreateUser.html
if !regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9_-]{2,31}$`).MatchString(value) {
errors = append(errors, fmt.Errorf("Invalid %q: must be between 3 and 32 alphanumeric or special characters hyphen and underscore. However, %q cannot begin with a hyphen", k, k))
if !regexp.MustCompile(`^[a-zA-Z0-9_][a-zA-Z0-9_-]{2,99}$`).MatchString(value) {
errors = append(errors, fmt.Errorf("Invalid %q: must be between 3 and 100 alphanumeric or special characters hyphen and underscore. However, %q cannot begin with a hyphen", k, k))
}
return
}
Expand Down