Merge pull request #2516 from TimeIncOSS/f-aws-db-instance-id-validation

provider/aws: Add validation for aws_db_instance.identifier
This commit is contained in:
Radek Simko 2015-06-26 15:30:08 +01:00
commit 4230a524a4
1 changed files with 20 additions and 0 deletions

View File

@ -74,6 +74,26 @@ func resourceAwsDbInstance() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: 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 !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"))
}
return
},
}, },
"instance_class": &schema.Schema{ "instance_class": &schema.Schema{