mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
Merge pull request #2513 from TimeIncOSS/f-aws-validation-db-subnet-group
aws: Add validation for aws_db_subnet_group.name
This commit is contained in:
commit
4a14d83733
@ -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
|
||||
},
|
||||
|
@ -3,6 +3,7 @@ package aws
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user