-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add delete_protection to SQL Instances + Service Networking Pre Create Checks #3954
Add delete_protection to SQL Instances + Service Networking Pre Create Checks #3954
Conversation
Hello! I am a robot who works on Magic Modules PRs. I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review. Thanks for your contribution! A human will be with you soon. @ndmckinley, please review this PR or find an appropriate assignee. |
So, tests are failing for the deletion_protection but the service networking check is passing.
The other test is complaining of non empty plan but my approach is similar to #3450 so not sure what is going on.
|
third_party/terraform/resources/resource_sql_database_instance.go.erb
Outdated
Show resolved
Hide resolved
third_party/terraform/resources/resource_sql_database_instance.go.erb
Outdated
Show resolved
Hide resolved
Were you able to figure out the |
/gcbrun |
Yeah, still looks good on my end. I'm running the affected integration tests on our CI now. |
Almost there! You didn't update the regex for your error checker in the integration test:
|
Ah, this also breaks all the other SQL tests, because it introduces a permadiff - if deletion_protection is unset, it will always show a diff. |
:( I have updated the regex, any ideas on the permadiff? |
Aha. I think it's probably an odd manifestation of the fact that you have the type set to TypeString when it should be a boolean. |
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, running the tests again now.
Okay, all the integration tests still fail with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the detailed drive-by- I happened to notice this PR and since I wrote the other deletion_protection one, I have some Opinions on what the right approach is :)
third_party/terraform/resources/resource_sql_database_instance.go.erb
Outdated
Show resolved
Hide resolved
@@ -121,6 +121,12 @@ func resourceSqlDatabaseInstance() *schema.Resource { | |||
Computed: true, | |||
Description: `Used to make sure changes to the settings block are atomic.`, | |||
}, | |||
"deletion_protection": { | |||
Type: schema.TypeBool, | |||
Default: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How useful is this field with a false
default? The reason why we added it to bigtable was to prevent people from accidentally destroying their instances because they didn't realize they should do a lifecycle prevent_destroy. If the default is false, wouldn't that just be equivalent to the prevent_destroy behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't consider that. I assumed that the users would set this true if they wanted to avoid terraform deleting their data. I never understood how the OP in 7072 blindly ran a plan that marked the instance for destruction and asked for more guardrails.
I'll set it to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fairness, Google doesn't stop the instance from being deleted if a database already exists on it which is strange considering Google requires dependant resource to be deleted before the parent resource is deleted. ie DNS Records in DNS Zones, VPC Networks, GCE Disk, etc
@@ -650,6 +656,26 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) | |||
|
|||
d.Set("name", name) | |||
|
|||
// Before we create the instance, check if at least 1 service connection exists for private SQL Instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is completely unrelated to the deletion protection one. In the future, changes like these two should be in separate PRs so they can be easily reviewed independently.
third_party/terraform/website/docs/r/sql_database_instance.html.markdown
Outdated
Show resolved
Hide resolved
Rerunning the tests now. |
The following tests still fail:
As well as two that are already failing:
|
I forgot about the other resources linked to it. I'll push a commit now |
I think i got them all |
Okay, I will run the tests overnight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests all pass. I updated the release notes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, one last thing:
==> Checking source code against linters...
google/resource_sql_database_instance.go:1062:7: Error return value of `d.Set` is not checked (errcheck)
d.Set("deletion_protection", true)
^
make: *** [lint] Error 1
it is fixed now |
@danawillow - are your requested changes made? GH wants all reviewers to approve before submitting - can you approve or dismiss your review if we're good to merge? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I updated the changelog message to use the correct resource and field names.
third_party/terraform/website/docs/r/sql_database_instance.html.markdown
Outdated
Show resolved
Hide resolved
I think we are ready to go. |
Not sure what changed, but
|
something snuck in when i merged master in to the branch, i'll fix it now |
i think we are good now. 😌 |
Fixes: hashicorp/terraform-provider-google#7072
Fixes: hashicorp/terraform-provider-google#7154
If this PR is for Terraform, I acknowledge that I have:
make test
andmake lint
to ensure it passes unit and linter tests.Release Note Template for Downstream PRs (will be copied)