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

Add enableDropProtection support to spanner database #8011

Merged
merged 12 commits into from
Jul 25, 2023
Merged

Add enableDropProtection support to spanner database #8011

merged 12 commits into from
Jul 25, 2023

Conversation

rahul2393
Copy link
Contributor

@rahul2393 rahul2393 commented May 24, 2023

Add support for setting enable_drop_protection on google_spanner_database

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Generated Terraform providers, and ran make test and make lint in the generated providers to ensure it passes unit and linter tests.
  • Ran relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

spanner: added `enable_drop_protection` to `google_spanner_database`

@modular-magician
Copy link
Collaborator

Oops! It looks like you're using an unknown release-note type in your changelog entries:

  • REPLACEME

Please only use the types listed in https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I've detected that you're a community contributor. @shuyama1, a repository maintainer, has been assigned to assist you and help review your changes.

❓ First time contributing? Click here for more details

Your assigned reviewer will help review your code by:

  • Ensuring it's backwards compatible, covers common error cases, etc.
  • Summarizing the change into a user-facing changelog note.
  • Passes tests, either our "VCR" suite, a set of presubmit tests, or with manual test runs.

You can help make sure that review is quick by running local tests and ensuring they're passing in between each push you make to your PR's branch. Also, try to leave a comment with each push you make, as pushes generally don't generate emails.

If your reviewer doesn't get back to you within a week after your most recent change, please feel free to leave a comment on the issue asking them to take a look! In the absence of a dedicated review dashboard most maintainers manage their pending reviews through email, and those will sometimes get lost in their inbox.


@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 2 files changed, 88 insertions(+))
Terraform Beta: Diff ( 2 files changed, 88 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_spanner_database (18 total tests)
Untested fields: enable_drop_protection

Please add acceptance tests which include these fields.

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2747
Passed tests 2457
Skipped tests: 283
Affected tests: 7

Action taken

Found 7 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccComputeFirewallPolicyRule_multipleRules|TestAccAlloydbCluster_missingLocation|TestAccAlloydbBackup_missingLocation|TestAccApigeeKeystoresAliasesPkcs12_ApigeeKeystoresAliasesPkcs12Example|TestAccDataSourceAlloydbLocations_basic|TestAccDataSourceGoogleFirebaseAndroidAppConfig|TestAccApigeeKeystoresAliasesKeyCertFile_apigeeKeystoresAliasesKeyCertFileTestExample

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccAlloydbCluster_missingLocation[Debug log]
TestAccAlloydbBackup_missingLocation[Debug log]
TestAccDataSourceAlloydbLocations_basic[Debug log]
TestAccDataSourceGoogleFirebaseAndroidAppConfig[Debug log]

Tests failed during RECORDING mode:
TestAccComputeFirewallPolicyRule_multipleRules[Error message] [Debug log]
TestAccApigeeKeystoresAliasesPkcs12_ApigeeKeystoresAliasesPkcs12Example[Error message] [Debug log]
TestAccApigeeKeystoresAliasesKeyCertFile_apigeeKeystoresAliasesKeyCertFileTestExample[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 2 files changed, 121 insertions(+))
Terraform Beta: Diff ( 2 files changed, 121 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_spanner_database (0 total tests)
Untested fields: enable_drop_protection

Please add acceptance tests which include these fields.

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2843
Passed tests 2502
Skipped tests: 295
Affected tests: 46

Action taken

Found 46 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccComputeRegionInstanceTemplate_with18TbScratchDisk|TestAccComputeRegionInstanceTemplate_withScratchDisk|TestAccComputeRegionInstanceTemplate_minCpuPlatform|TestAccComputeRegionInstanceTemplate_guestAcceleratorSkip|TestAccComputeRegionInstanceTemplate_guestAccelerator|TestAccComputeRegionInstanceTemplate_secondaryAliasIpRange|TestAccComputeRegionInstanceTemplate_primaryAliasIpRange|TestAccComputeRegionInstanceTemplate_metadata_startup_script|TestAccComputeRegionInstanceTemplate_subnet_custom|TestAccComputeRegionInstanceTemplate_subnet_auto|TestAccComputeInstanceTemplate_minCpuPlatform|TestAccComputeRegionInstanceTemplate_regionDisks|TestAccComputeInstanceFromTemplate_overrideAttachedDisk|TestAccComputeInstanceTemplate_guestAcceleratorSkip|TestAccComputeInstanceFromTemplate_overrideBootDisk|TestAccComputeInstanceTemplate_NetworkAttachment|TestAccComputeInstanceFromRegionTemplate_basic|TestAccContainerAwsNodePool_BetaBasicHandWritten|TestAccComputeInstanceTemplate_secondaryAliasIpRange|TestAccComputeInstanceFromTemplate_self_link_unique|TestAccContainerAwsNodePool_BasicHandWritten|TestAccComputeInstanceFromTemplate_basic|TestAccContainerAwsCluster_BetaBasicHandWritten|TestAccComputeInstanceTemplate_primaryAliasIpRange|TestAccContainerAwsCluster_BasicHandWritten|TestAccComputeInstanceTemplate_metadata_startup_script|TestAccComputeRegionAutoscaler_regionAutoscalerBasicExample|TestAccComputeInstanceTemplate_subnet_custom|TestAccComputeInstanceTemplate_subnet_auto|TestAccComputeInstanceTemplate_regionDisks|TestAccComputeInstanceTemplate_disks|TestAccComputeInstanceTemplate_guestAccelerator|TestAccComputeInstanceTemplate_with18TbScratchDisk|TestAccComputeInstanceTemplate_withScratchDisk|TestAccCloudbuildv2Connection_GleOldConnection|TestAccCloudbuildv2Connection_GleConnection|TestAccComputeFirewallPolicyRule_multipleRules|TestAccCloudbuildv2Connection_GitlabConnection|TestAccClouddeployDeliveryPipeline_CanaryrunDeliveryPipeline|TestAccClouddeployDeliveryPipeline_CanaryServiceNetworkingDeliveryPipeline|TestAccComputeInstanceFromTemplate_012_removableFields|TestAccComputeInstanceFromTemplate_overrideScratchDisk|TestAccClouddeployDeliveryPipeline_CanaryDeliveryPipeline|TestAccCloudbuildv2Connection_GlePrivUpdateConnection|TestAccClouddeployDeliveryPipeline_DeliveryPipeline|TestAccCloudbuildv2Connection_GlePrivConnection

Get to know how VCR tests work

@shuyama1
Copy link
Member

shuyama1 commented Jul 7, 2023

tests got timed out. rerun now
/gcbrun

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 2 files changed, 121 insertions(+))
Terraform Beta: Diff ( 2 files changed, 121 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_spanner_database (0 total tests)
Untested fields: enable_drop_protection

Please add acceptance tests which include these fields.

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

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

Can you add a test on it? We require that every field have at least one test coverage if feasible. You can modify an existing one in https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/third_party/terraform/tests/resource_spanner_database_test.go.erb.

Plus, since this field support in-place update, can you also include this in an update step?
More details on https://googlecloudplatform.github.io/magic-modules/develop/add-handwritten-test/#update-tests

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2830
Passed tests 2533
Skipped tests: 295
Affected tests: 2

Action taken

Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccContainerAwsNodePool_BetaBasicHandWritten|TestAccComputeFirewallPolicyRule_multipleRules

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

Tests failed during RECORDING mode:
TestAccContainerAwsNodePool_BetaBasicHandWritten[Error message] [Debug log]
TestAccComputeFirewallPolicyRule_multipleRules[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 135 insertions(+))
Terraform Beta: Diff ( 3 files changed, 135 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2848
Passed tests 2548
Skipped tests: 295
Affected tests: 5

Action taken

Found 5 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccSpannerDatabase_enableDropProtection|TestAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample|TestAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample|TestAccContainerAwsNodePool_BetaBasicHandWritten|TestAccComputeFirewallPolicyRule_multipleRules

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccComputeTargetHttpsProxy_targetHttpsProxyHttpKeepAliveTimeoutExample[Debug log]
TestAccComputeTargetHttpProxy_targetHttpProxyHttpKeepAliveTimeoutExample[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccSpannerDatabase_enableDropProtection[Error message] [Debug log]
TestAccContainerAwsNodePool_BetaBasicHandWritten[Error message] [Debug log]
TestAccComputeFirewallPolicyRule_multipleRules[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$
View the build log or the debug log for each test

Comment on lines 77 to 105
enableDropProtection, enableDropProtectionOk := d.GetOk("enable_drop_protection")
dropProtection := enableDropProtection.(bool)
if enableDropProtectionOk && dropProtection {
updateMask := []string{"enableDropProtection"}
url, err := tpgresource.ReplaceVars(d, config, "{{SpannerBasePath}}projects/{{project}}/instances/{{instance}}/databases/{{name}}")
if err != nil {
return err
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}
res, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PATCH",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})
if err != nil {
return fmt.Errorf("Error updating enableDropDatabaseProtection on Database: %s", err)
} else {
log.Printf("[DEBUG] Finished updating enableDropDatabaseProtection %q: %#v", d.Id(), res)
}
Copy link
Member

Choose a reason for hiding this comment

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

qq: why do we need it for creation?

Copy link
Contributor Author

@rahul2393 rahul2393 Jul 11, 2023

Choose a reason for hiding this comment

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

The create database API does not support setting enableDropProtection, so we need to make separate request using this https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases/patch

@rahul2393
Copy link
Contributor Author

/gcbrun

@shuyama1
Copy link
Member

@rahul2393 would you mind rebasing your PR?

@shuyama1
Copy link
Member

@rahul2393 small question regarding the field: I can't find API documentation of the field, but my assumption is that if we set this field to true, we will prevent the database from deletion? We've already have a Terraform side deletion_protection for resource for same purpose (opposite default logic though) and it set to true as default to prevent users from deleting databases and now we are just implementing the server-side protection?

@rahul2393
Copy link
Contributor Author

@rahul2393 small question regarding the field: I can't find API documentation of the field, but my assumption is that if we set this field to true, we will prevent the database from deletion? We've already have a Terraform side deletion_protection for resource for same purpose (opposite default logic though) and it set to true as default to prevent users from deleting databases and now we are just implementing the server-side protection?

Yes, this is for server side protection and since we don't want it to be breaking change so we will support both the fields for now, and plan is to put deprecation message/comment on existing virtual field

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 207 insertions(+))
Terraform Beta: Diff ( 3 files changed, 207 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 212 insertions(+))
Terraform Beta: Diff ( 3 files changed, 212 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@rahul2393
Copy link
Contributor Author

/gcbrun

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 218 insertions(+))
Terraform Beta: Diff ( 3 files changed, 218 insertions(+))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 267 insertions(+), 30 deletions(-))
Terraform Beta: Diff ( 3 files changed, 267 insertions(+), 30 deletions(-))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2872
Passed tests 2570
Skipped tests: 299
Affected tests: 3

Action taken

Found 3 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccProjectIamPolicy_invalidMembers|TestAccContainerAwsNodePool_BetaBasicHandWritten|TestAccSpannerDatabase_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccProjectIamPolicy_invalidMembers[Debug log]
TestAccSpannerDatabase_basic[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccContainerAwsNodePool_BetaBasicHandWritten[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$
View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 264 insertions(+), 30 deletions(-))
Terraform Beta: Diff ( 3 files changed, 264 insertions(+), 30 deletions(-))
TF Conversion: Diff ( 3 files changed, 13 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2872
Passed tests 2571
Skipped tests: 299
Affected tests: 2

Action taken

Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccContainerAwsNodePool_BetaBasicHandWritten|TestAccFolderIamPolicy_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccFolderIamPolicy_basic[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccContainerAwsNodePool_BetaBasicHandWritten[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$
View the build log or the debug log for each test

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants