From 5796b133730973d16ad2143d4aca1e081d13f19e Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 10 Nov 2015 23:05:07 +0000 Subject: [PATCH] Adding skip_final_snapshop bool to th db_instance. This will allow us to specify whether a snapshot is needed directly rather than checking for an empty string --- .../providers/aws/resource_aws_db_instance.go | 16 +++++++++++----- .../providers/aws/r/db_instance.html.markdown | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index c078b5791..ac6205cd2 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -188,6 +188,12 @@ func resourceAwsDbInstance() *schema.Resource { }, }, + "skip_final_snapshot": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "copy_tags_to_snapshot": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -619,11 +625,11 @@ func resourceAwsDbInstanceDelete(d *schema.ResourceData, meta interface{}) error opts := rds.DeleteDBInstanceInput{DBInstanceIdentifier: aws.String(d.Id())} - finalSnapshot := d.Get("final_snapshot_identifier").(string) - if finalSnapshot == "" { - opts.SkipFinalSnapshot = aws.Bool(true) - } else { - opts.FinalDBSnapshotIdentifier = aws.String(finalSnapshot) + skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) + opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot) + + if name, present := d.GetOk("final_snapshot_identifier"); present && !skipFinalSnapshot { + opts.FinalDBSnapshotIdentifier = aws.String(name.(string)) } log.Printf("[DEBUG] DB Instance destroy configuration: %v", opts) diff --git a/website/source/docs/providers/aws/r/db_instance.html.markdown b/website/source/docs/providers/aws/r/db_instance.html.markdown index 7f36f3385..8cf95de3a 100644 --- a/website/source/docs/providers/aws/r/db_instance.html.markdown +++ b/website/source/docs/providers/aws/r/db_instance.html.markdown @@ -45,6 +45,7 @@ The following arguments are supported: * `final_snapshot_identifier` - (Optional) The name of your final DB snapshot when this DB instance 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 instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted. Default is false. * `copy_tags_to_snapshot` – (Optional, boolean) On delete, copy all Instance `tags` to the final snapshot (if `final_snapshot_identifier` is specified). Default `false`