Skip to content

Commit

Permalink
Merge pull request #2517 from TimeIncOSS/f-aws-elb-validation
Browse files Browse the repository at this point in the history
provider/aws: Add validation for aws_elb.name
  • Loading branch information
radeksimko committed Jun 26, 2015
2 parents 4980148 + 6f2fb0d commit 7217a37
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions builtin/providers/aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -25,6 +26,26 @@ func resourceAwsElb() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: 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) > 32 {
errors = append(errors, fmt.Errorf(
"%q cannot be longer than 32 characters", k))
}
if regexp.MustCompile(`^-`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot begin with a hyphen", k))
}
if regexp.MustCompile(`-$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot end with a hyphen", k))
}
return
},
},

"internal": &schema.Schema{
Expand Down

0 comments on commit 7217a37

Please sign in to comment.