Skip to content

Commit

Permalink
Merge pull request #2513 from TimeIncOSS/f-aws-validation-db-subnet-g…
Browse files Browse the repository at this point in the history
…roup

aws: Add validation for aws_db_subnet_group.name
  • Loading branch information
phinze committed Jun 26, 2015
2 parents 0aa1854 + ca83dc2 commit 4a14d83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 7 additions & 7 deletions builtin/providers/aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ func resourceAwsDbInstance() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
fsi := v.(string)
if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(fsi) {
value := v.(string)
if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(value) {
es = append(es, fmt.Errorf(
"only alphanumeric characters and hyphens allowed in %s", k))
"only alphanumeric characters and hyphens allowed in %q", k))
}
if regexp.MustCompile(`--`).MatchString(fsi) {
es = append(es, fmt.Errorf("%s cannot contain two consecutive hyphens", k))
if regexp.MustCompile(`--`).MatchString(value) {
es = append(es, fmt.Errorf("%q cannot contain two consecutive hyphens", k))
}
if regexp.MustCompile(`-$`).MatchString(fsi) {
es = append(es, fmt.Errorf("%s cannot end in a hyphen", k))
if regexp.MustCompile(`-$`).MatchString(value) {
es = append(es, fmt.Errorf("%q cannot end in a hyphen", k))
}
return
},
Expand Down
17 changes: 17 additions & 0 deletions builtin/providers/aws/resource_aws_db_subnet_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"regexp"
"strings"
"time"

Expand All @@ -24,6 +25,22 @@ func resourceAwsDbSubnetGroup() *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 len(value) > 255 {
errors = append(errors, fmt.Errorf(
"%q cannot be longer than 255 characters", k))
}
if regexp.MustCompile(`(?i)^default$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q is not allowed as %q", "Default", k))
}
return
},
},

"description": &schema.Schema{
Expand Down

0 comments on commit 4a14d83

Please sign in to comment.