From 8e7ed4daacc8523ff12104ca62b96be77509d9e4 Mon Sep 17 00:00:00 2001 From: Angel Abad Date: Mon, 14 Sep 2020 16:22:34 +0200 Subject: [PATCH] resource/aws_db_cluster_snapshot: Add plan-time validation for db_cluster_snapshot_identifier argument (#15132) Output from acceptance testing: ``` --- PASS: TestAccAWSDBClusterSnapshot_basic (177.55s) --- PASS: TestAccAWSDBClusterSnapshot_Tags (194.42s) ``` --- 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,