Skip to content

Commit 9f4513f

Browse files
authored
Merge pull request #16885 from hashicorp/b-final-snapshot-identifier-validation
resource/db_instance: include check for first char in final_snapshot_identifier ValidationFunc
2 parents 0a8302e + e378231 commit 9f4513f

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

aws/resource_aws_db_instance.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,12 @@ func resourceAwsDbInstance() *schema.Resource {
263263
"final_snapshot_identifier": {
264264
Type: schema.TypeString,
265265
Optional: true,
266-
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
267-
value := v.(string)
268-
if !regexp.MustCompile(`^[0-9A-Za-z-]+$`).MatchString(value) {
269-
es = append(es, fmt.Errorf(
270-
"only alphanumeric characters and hyphens allowed in %q", k))
271-
}
272-
if regexp.MustCompile(`--`).MatchString(value) {
273-
es = append(es, fmt.Errorf("%q cannot contain two consecutive hyphens", k))
274-
}
275-
if regexp.MustCompile(`-$`).MatchString(value) {
276-
es = append(es, fmt.Errorf("%q cannot end in a hyphen", k))
277-
}
278-
return
279-
},
266+
ValidateFunc: validation.All(
267+
validation.StringMatch(regexp.MustCompile(`^[A-Za-z]`), "must begin with alphabetic character"),
268+
validation.StringMatch(regexp.MustCompile(`^[0-9A-Za-z-]+$`), "must only contain alphanumeric characters and hyphens"),
269+
validation.StringDoesNotMatch(regexp.MustCompile(`--`), "cannot contain two consecutive hyphens"),
270+
validation.StringDoesNotMatch(regexp.MustCompile(`-$`), "cannot end in a hyphen"),
271+
),
280272
},
281273

282274
"restore_to_point_in_time": {

aws/resource_aws_db_instance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func TestAccAWSDBInstance_FinalSnapshotIdentifier(t *testing.T) {
442442
PreCheck: func() { testAccPreCheck(t) },
443443
Providers: testAccProviders,
444444
// testAccCheckAWSDBInstanceSnapshot verifies a database snapshot is
445-
// created, and subequently deletes it
445+
// created, and subsequently deletes it
446446
CheckDestroy: testAccCheckAWSDBInstanceSnapshot,
447447
Steps: []resource.TestStep{
448448
{

website/docs/r/db_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ For supported values, see the EngineVersion parameter in [API action CreateDBIns
120120
Note that for Amazon Aurora instances the engine version must match the [DB cluster](/docs/providers/aws/r/rds_cluster.html)'s engine version'.
121121
* `final_snapshot_identifier` - (Optional) The name of your final DB snapshot
122122
when this DB instance is deleted. Must be provided if `skip_final_snapshot` is
123-
set to `false`.
123+
set to `false`. The value must begin with a letter, only contain alphanumeric characters and hyphens, and not end with a hyphen or contain two consecutive hyphens. Must not be provided when deleting a read replica.
124124
* `iam_database_authentication_enabled` - (Optional) Specifies whether or
125125
mappings of AWS Identity and Access Management (IAM) accounts to database
126126
accounts is enabled.

0 commit comments

Comments
 (0)