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

Remove underscores from RDS parameter group name validation #3396

Merged
merged 1 commit into from
Feb 16, 2018
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
44 changes: 0 additions & 44 deletions aws/resource_aws_db_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,50 +435,6 @@ func TestAccAWSDBParameterGroup_MatchDefault(t *testing.T) {
})
}

func TestResourceAWSDBParameterGroupName_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "tEsting123",
ErrCount: 1,
},
{
Value: "testing123!",
ErrCount: 1,
},
{
Value: "1testing123",
ErrCount: 1,
},
{
Value: "testing--123",
ErrCount: 1,
},
{
Value: "testing__123",
ErrCount: 1,
},
{
Value: "testing123-",
ErrCount: 1,
},
{
Value: randomString(256),
ErrCount: 1,
},
}

for _, tc := range cases {
_, errors := validateDbParamGroupName(tc.Value, "aws_db_parameter_group_name")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
}

func testAccCheckAWSDbParamaterGroupDisappears(v *rds.DBParameterGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).rdsconn
Expand Down
40 changes: 0 additions & 40 deletions aws/resource_aws_rds_cluster_parameter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,46 +178,6 @@ func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) {
})
}

func TestResourceAWSDBClusterParameterGroupName_validation(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "tEsting123",
ErrCount: 1,
},
{
Value: "testing123!",
ErrCount: 1,
},
{
Value: "1testing123",
ErrCount: 1,
},
{
Value: "testing--123",
ErrCount: 1,
},
{
Value: "testing123-",
ErrCount: 1,
},
{
Value: randomString(256),
ErrCount: 1,
},
}

for _, tc := range cases {
_, errors := validateDbParamGroupName(tc.Value, "aws_rds_cluster_parameter_group_name")

if len(errors) != tc.ErrCount {
t.Fatal("Expected the DB Cluster Parameter Group Name to trigger a validation error")
}
}
}

func testAccCheckAWSDBClusterParameterGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).rdsconn

Expand Down
8 changes: 2 additions & 6 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func validateTagFilters(v interface{}, k string) (ws []string, errors []error) {

func validateDbParamGroupName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9a-z-_]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters, underscores and hyphens allowed in %q", k))
"only lowercase alphanumeric characters and hyphens allowed in %q", k))
}
if !regexp.MustCompile(`^[a-z]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
Expand All @@ -148,10 +148,6 @@ func validateDbParamGroupName(v interface{}, k string) (ws []string, errors []er
errors = append(errors, fmt.Errorf(
"%q cannot contain two consecutive hyphens", k))
}
if regexp.MustCompile(`__`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot contain two consecutive underscores", k))
}
if regexp.MustCompile(`-$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot end with a hyphen", k))
Expand Down
44 changes: 44 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,50 @@ func TestValidateDbOptionGroupNamePrefix(t *testing.T) {
}
}

func TestValidateDbParamGroupName(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "tEsting123",
ErrCount: 1,
},
{
Value: "testing123!",
ErrCount: 1,
},
{
Value: "1testing123",
ErrCount: 1,
},
{
Value: "testing--123",
ErrCount: 1,
},
{
Value: "testing_123",
ErrCount: 1,
},
{
Value: "testing123-",
ErrCount: 1,
},
{
Value: randomString(256),
ErrCount: 1,
},
}

for _, tc := range cases {
_, errors := validateDbParamGroupName(tc.Value, "aws_db_parameter_group_name")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
}

func TestValidateOpenIdURL(t *testing.T) {
cases := []struct {
Value string
Expand Down