Skip to content

Commit

Permalink
resource/aws_db_cluster_snapshot: Add plan-time validation for db_clu…
Browse files Browse the repository at this point in the history
…ster_snapshot_identifier argument (#15132)

Output from acceptance testing:

```
--- PASS: TestAccAWSDBClusterSnapshot_basic (177.55s)
--- PASS: TestAccAWSDBClusterSnapshot_Tags (194.42s)
```
  • Loading branch information
angelabad committed Sep 14, 2020
1 parent 69c8a5d commit 8e7ed4d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_db_cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down

0 comments on commit 8e7ed4d

Please sign in to comment.