From 3a9852568ae2787881b9f3e9961b2e074da9e431 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 25 Jun 2015 11:06:16 +0100 Subject: [PATCH] provider/aws: Add validation for aws_db_instance.identifier --- .../providers/aws/resource_aws_db_instance.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 078ce229f..008137afa 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -74,6 +74,26 @@ func resourceAwsDbInstance() *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 !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{