From 765be4c768ac64d49006bbcccb04236e1ff05a93 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 25 Jun 2015 11:06:00 +0100 Subject: [PATCH 1/2] provider/aws: Fix naming in validation of db_instance.final_snapshot_identifier --- builtin/providers/aws/resource_aws_db_instance.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index ea21a8e1e819..078ce229f2c6 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -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 }, From ca83dc21183644fd2407961c5d6f8586380ca092 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 25 Jun 2015 10:57:21 +0100 Subject: [PATCH 2/2] provider/aws: Add validation for aws_db_subnet_group.name --- .../aws/resource_aws_db_subnet_group.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_subnet_group.go b/builtin/providers/aws/resource_aws_db_subnet_group.go index 5d49e91511b4..853e94315162 100644 --- a/builtin/providers/aws/resource_aws_db_subnet_group.go +++ b/builtin/providers/aws/resource_aws_db_subnet_group.go @@ -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{