From e84ea061e3e02281289ec2543eb27cc417cfa5af Mon Sep 17 00:00:00 2001 From: Angel Abad Date: Sat, 12 Sep 2020 16:59:23 +0200 Subject: [PATCH] resource/aws_db_cluster_snapshot: Add validation for db_cluster_snapshot_identifier --- aws/resource_aws_db_cluster_snapshot.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/aws/resource_aws_db_cluster_snapshot.go b/aws/resource_aws_db_cluster_snapshot.go index 302afb3ac623..c7377b9bdc42 100644 --- a/aws/resource_aws_db_cluster_snapshot.go +++ b/aws/resource_aws_db_cluster_snapshot.go @@ -3,12 +3,14 @@ package aws import ( "fmt" "log" + "regexp" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) @@ -33,6 +35,13 @@ func resourceAwsDbClusterSnapshot() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 63), + validation.StringMatch(regexp.MustCompile(`^[0-9a-z-]+$`), "must contain only lowercase alphanumeric characters and hyphens"), + validation.StringMatch(regexp.MustCompile(`^[a-z]`), "must begin with a lowercase letter"), + validation.StringDoesNotMatch(regexp.MustCompile(`--`), "cannot contain two consecutive hyphens"), + validation.StringDoesNotMatch(regexp.MustCompile(`-$`), "cannot end with a hyphen"), + ), }, "db_cluster_identifier": { Type: schema.TypeString,