From c753c1e91dd9aa3af5ea33a37bd7a6a825c92603 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 18 Sep 2015 13:04:33 +0100 Subject: [PATCH] Changing the PR for the db_param_group to ensure validation rather than documentation --- .../aws/resource_aws_db_parameter_group.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_parameter_group.go b/builtin/providers/aws/resource_aws_db_parameter_group.go index b274605a7793..72101ac90893 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "log" + "regexp" "strings" "time" @@ -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,