Skip to content

Commit

Permalink
Merge pull request #3279 from stack72/aws-db_param_group_lowercase
Browse files Browse the repository at this point in the history
provider/aws: db_parameter_group name validation
  • Loading branch information
radeksimko committed Oct 8, 2015
2 parents 7cb395c + c753c1e commit 96dc244
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions builtin/providers/aws/resource_aws_db_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"regexp"
"strings"
"time"

Expand All @@ -27,6 +28,30 @@ func resourceAwsDbParameterGroup() *schema.Resource {
Type: schema.TypeString,
ForceNew: true,
Required: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters and hyphens allowed in %q", k))
}
if !regexp.MustCompile(`^[a-z]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"first character of %q must be a letter", k))
}
if regexp.MustCompile(`--`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot contain two consecutive hyphens", k))
}
if regexp.MustCompile(`-$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot end with a hyphen", k))
}
if len(value) > 255 {
errors = append(errors, fmt.Errorf(
"%q cannot be greater than 255 characters", k))
}
return
},
},
"family": &schema.Schema{
Type: schema.TypeString,
Expand Down

0 comments on commit 96dc244

Please sign in to comment.