Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: DB Instance skip_final_snapshot #3853

Merged
merged 3 commits into from
Dec 10, 2015

Conversation

stack72
Copy link
Contributor

@stack72 stack72 commented Nov 10, 2015

Fixes #3848

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

Added as per the docs rather than checking for an empty string on final_snapshot_identifier

} else {
skipFinalSnapshot := d.Get("skip_final_snapshot").(bool)
opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot)
if !skipFinalSnapshot && d.Get("final_snapshot_identifier").(string) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unverified but I think you might be able to use GetOk here instead of Get and avoid the check.

@jen20
Copy link
Contributor

jen20 commented Nov 10, 2015

@stack72 I think this is the correct approach versus special casing the final snapshot name, but I'll leave it up to @catsby or @phinze to have a final say on this as they're more likely to know of precedent that may have been set elsewhere in Terraform. I've made a few comments inline with respect to the code if this is the correct approach.

opts.SkipFinalSnapshot = aws.Bool(skipFinalSnapshot)

if name, present := d.GetOk("final_snapshot_identifier"); present && !skipFinalSnapshot {
opts.FinalDBSnapshotIdentifier = aws.String(name.(string))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user has skip_final_snapshot = false in their config, but omits final_snapshot_identifier (valid config as we have things now), then no final snapshot will be taken. We should error in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense :) Adding it now

@catsby
Copy link
Contributor

catsby commented Nov 11, 2015

Thanks for the PR @stack72! I have some questions though. As it stands I don't think this is a good move, but I'm open for discussing it.

Currently, if the user wants a final snapshot before deleting, the must specify the identifier in their config, or no snapshot will be taken.

The proposed change is an optional parameter with default of false. So, the situation hasn't changed, has it? If they want a backup they must supply a final snapshot identifier. They don't have to specify skip_final_snapshot, because false is the value you want if you want a final snapshot.

Specifying true to skip the final backup then seems unnecessary. In this situation you would also not specify a final snapshot identifier (I would suspect).

I pointed out above in a code comment that as it stands, specifying skip_final_snapshot without providing a final_snapshot_identifier will result in no final snapshot being taken. Even if that's addressed, I think there is a backwards compatibility change introduced. If I do not specify final_snapshot_identifier on v0.6.6, I can create and delete without interruption. With this proposed change, I cannot create in v0.6.6 and delete after upgrading to this change. Manual intervention is required, either to specify final_snapshot_identifier or specify skip_final_snapshot. That's not a deal breaker, or even a breaking change really, but I don't feel it's insignificant.

What are your thoughts on these?

@catsby catsby added the waiting-response An issue/pull request is waiting for a response from the community label Nov 11, 2015
@stack72
Copy link
Contributor Author

stack72 commented Nov 11, 2015

@catsby I am just trying to solve the problem from the original issue - I haven't personally come up against the issue as we always take a snapshot. I think if you have a think about the original issue (linked) then I am happy to go whatever way you think is necessary

@catsby
Copy link
Contributor

catsby commented Nov 11, 2015

Reading up on #3848 and re-thinking, perhaps this is a thing we do need. I think skip_final_snapshot should default to true, since that's our behavior right now (albeit the AWS default is false, an instance where we go against the grain here).

If we default to true, we preserve the current behavior; omitting final_snapshot_identifier and skip_final_snapshot, you get the same behavior. Defaulting to true will make it easier to error if no identifier is given, since the user would need to specify false and an identifier to get the backup.

Does that sound reasonable? I think that would address #3848 by allowing that user to leave their final_snapshot_identifier as is, and then include skip_final_snapshot = ${var.skip_final} or similar, and toggle that variable based on environment. cc @phinze and @jen20 for sanity check

@stack72
Copy link
Contributor Author

stack72 commented Nov 11, 2015

@catsby agree with this approach - this would mean no backwards functionality changes which rocks :)

@jen20
Copy link
Contributor

jen20 commented Nov 11, 2015

👍 for preserving current behaviour here. This looks good to me. One thing - is it worth an acceptance test here to prevent regression since there is some (albeit simple) logic and the worst case is a snapshot not being made where one is expected?

@catsby
Copy link
Contributor

catsby commented Nov 16, 2015

Agree an acceptance test would be best here... I'm not sure how to do it though, thoughts? Create two instances, one without skip and the other skip = false, then query in a check to make sure there is a snapshot being made for the latter, and not the former? And then delete it to not leak?

@phinze
Copy link
Contributor

phinze commented Dec 2, 2015

That description sounds right, @catsby. It's a bit of a dance, but it would be nice to cover the snapshot behavior since it's really important to get that right for prod databases. 😀

@stack72
Copy link
Contributor Author

stack72 commented Dec 2, 2015

I'll get this test added over the weekend :)

@stack72 stack72 changed the title provider/aws: DB Instance skip_final_snapshot [WIP] provider/aws: DB Instance skip_final_snapshot Dec 9, 2015
@stack72 stack72 force-pushed the f-aws-db-instance-omit-snapshot branch from cc5d21f to 2b0c7aa Compare December 10, 2015 23:21
@stack72
Copy link
Contributor Author

stack72 commented Dec 10, 2015

@jen20 / @catsby / @phinze finally got around to writing some tests for this. The Snapshot test cleans up after itself and deletes the snapshot in the CheckDestroy func

Creating a final Snapshot

TF_LOG=1 make testacc TEST=./builtin/providers/aws TESTARGS='-run=AWSDBInstanceSnapshot' 2>~/tf.log
go generate ./...
TF_ACC=1 go test ./builtin/providers/aws -v -run=AWSDBInstanceSnapshot -timeout 90m
=== RUN   TestAccAWSDBInstanceSnapshot
--- PASS: TestAccAWSDBInstanceSnapshot (951.31s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    951.323s

Skipping a final snapshot

TF_LOG=1 make testacc TEST=./builtin/providers/aws TESTARGS='-run=AWSDBInstanceNoSnapshot' 2>~/tf.log
go generate ./...
TF_ACC=1 go test ./builtin/providers/aws -v -run=AWSDBInstanceNoSnapshot -timeout 90m
=== RUN   TestAccAWSDBInstanceNoSnapshot
--- PASS: TestAccAWSDBInstanceNoSnapshot (939.14s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    939.160s

Build is currently running :)

@stack72 stack72 changed the title [WIP] provider/aws: DB Instance skip_final_snapshot provider/aws: DB Instance skip_final_snapshot Dec 10, 2015
@jen20
Copy link
Contributor

jen20 commented Dec 10, 2015

LGTM. Thanks @stack72!

jen20 added a commit that referenced this pull request Dec 10, 2015
provider/aws: add DB Instance skip_final_snapshot
@jen20 jen20 merged commit fb4878c into hashicorp:master Dec 10, 2015
@stack72 stack72 deleted the f-aws-db-instance-omit-snapshot branch December 10, 2015 23:39
@ghost
Copy link

ghost commented Apr 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow AWS_DB_INSTANCE final_snapshot_identifier to accept empty string as omitted.
4 participants