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,