From 37b234e42bbff227db131e8fa1dcfe0196864f0e Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Sun, 7 Jun 2015 20:49:48 -0500 Subject: [PATCH] provider/aws: validate RDS final_snapshot_identifier fixes #2250 --- builtin/providers/aws/resource_aws_db_instance.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 705b773f9..10cce3fd5 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "regexp" "strings" "time" @@ -153,6 +154,20 @@ func resourceAwsDbInstance() *schema.Resource { "final_snapshot_identifier": &schema.Schema{ Type: schema.TypeString, Optional: true, + ValidateFunc: func(v interface{}) (ws []string, es []error) { + fsi := v.(string) + if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(fsi) { + es = append(es, fmt.Errorf( + "only alphanumeric characters and hyphens allowed")) + } + if regexp.MustCompile(`--`).MatchString(fsi) { + es = append(es, fmt.Errorf("cannot contain two consecutive hyphens")) + } + if regexp.MustCompile(`-$`).MatchString(fsi) { + es = append(es, fmt.Errorf("cannot end in a hyphen")) + } + return + }, }, "db_subnet_group_name": &schema.Schema{