From 5a3a06154fd5377688f95d6f84ae09e0ac27a2e7 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 20 May 2016 14:43:45 +0100 Subject: [PATCH 1/2] provider/aws: Add support for Skipping Final Snapshot in RDS Cluster This works exactly the same as in DB Instance. We cannot use an empty string to skip the final snapshot or we get the following error: ``` only alphanumeric characters and hyphens allowed in "final_snapshot_identifier" ``` Therefore, we need to wrap this with another parameter. The we skip final snapshots by default as we do this currently and this would change the user functionality --- .../providers/aws/resource_aws_rds_cluster.go | 21 +++++++++++++------ .../providers/aws/r/rds_cluster.html.markdown | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_rds_cluster.go b/builtin/providers/aws/resource_aws_rds_cluster.go index 06104082ead1..74f7e3014c3e 100644 --- a/builtin/providers/aws/resource_aws_rds_cluster.go +++ b/builtin/providers/aws/resource_aws_rds_cluster.go @@ -103,6 +103,12 @@ func resourceAwsRDSCluster() *schema.Resource { }, }, + "skip_final_snapshot": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "master_username": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -372,12 +378,15 @@ func resourceAwsRDSClusterDelete(d *schema.ResourceData, meta interface{}) error DBClusterIdentifier: aws.String(d.Id()), } - finalSnapshot := d.Get("final_snapshot_identifier").(string) - if finalSnapshot == "" { - deleteOpts.SkipFinalSnapshot = aws.Bool(true) - } else { - deleteOpts.FinalDBSnapshotIdentifier = aws.String(finalSnapshot) - deleteOpts.SkipFinalSnapshot = aws.Bool(false) + skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) + deleteOpts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot) + + if skipFinalSnapshot == false { + if name, present := d.GetOk("final_snapshot_identifier"); present { + deleteOpts.FinalDBSnapshotIdentifier = aws.String(name.(string)) + } else { + return fmt.Errorf("RDS Cluster FinalSnapshotIdentifier is required when a final snapshot is required") + } } log.Printf("[DEBUG] RDS Cluster delete options: %s", deleteOpts) diff --git a/website/source/docs/providers/aws/r/rds_cluster.html.markdown b/website/source/docs/providers/aws/r/rds_cluster.html.markdown index 14e2d7b6d080..f1b0add768d6 100644 --- a/website/source/docs/providers/aws/r/rds_cluster.html.markdown +++ b/website/source/docs/providers/aws/r/rds_cluster.html.markdown @@ -61,6 +61,7 @@ string. * `final_snapshot_identifier` - (Optional) The name of your final DB snapshot when this DB cluster is deleted. If omitted, no final snapshot will be made. +* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted. Default is true. * `availability_zones` - (Optional) A list of EC2 Availability Zones that instances in the DB cluster can be created in * `backup_retention_period` - (Optional) The days to retain backups for. Default From 03c3957309190c4abf26e18ce0f90ec696498170 Mon Sep 17 00:00:00 2001 From: Clint Date: Fri, 20 May 2016 12:21:49 -0500 Subject: [PATCH 2/2] Update rds_cluster.html.markdown --- website/source/docs/providers/aws/r/rds_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/providers/aws/r/rds_cluster.html.markdown b/website/source/docs/providers/aws/r/rds_cluster.html.markdown index f1b0add768d6..852c37be977e 100644 --- a/website/source/docs/providers/aws/r/rds_cluster.html.markdown +++ b/website/source/docs/providers/aws/r/rds_cluster.html.markdown @@ -61,7 +61,7 @@ string. * `final_snapshot_identifier` - (Optional) The name of your final DB snapshot when this DB cluster is deleted. If omitted, no final snapshot will be made. -* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted. Default is true. +* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from `final_snapshot_identifier`. Default is true. * `availability_zones` - (Optional) A list of EC2 Availability Zones that instances in the DB cluster can be created in * `backup_retention_period` - (Optional) The days to retain backups for. Default