This repository has been archived by the owner on May 15, 2023. It is now read-only.
Add version retention period to Spanner database resource #799
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes hashicorp/terraform-provider-google#8994
This PR lets Terraform users set the retention period of historical versions of a Spanner database's data and schema for point in time recovery (PITR).
The retention period of the data used for PITR can be changed by running a DDL statement to update the database's options:
See usage notes section here & docs about equivalent DDL for Postgres
These DDL statements can be sent through the REST API and executed at either:
create
endpointextraStatements
array in the request bodyextraStatements
in the create request for a Postgres database, you get this error:DDL statements other than <CREATE DATABASE> are not allowed in database creation request for PostgreSQL-enabled databases
updateDdl
endpointApproach
I've used the value of the
version_retention_period
field to create an ALTER DDL statement like above and add it to the array of statements in the request bodies of requests sent to thecreate
orupdateDdl
endpointsEdit 2022-06-27 : I refactored the code for creating databases so that DDL statements (both originating from
ddl
andversion_retention_period
fields) are executed in the database via a separate API call. After the database is made using thecreate
endpoint the provider runs DDL against the new database using theupdateDdl
endpoint, all within the creation process in Terraform.Postgres issues
The DDL restriction when making Postgres databases has been met by the initial version of this PR by skipping setting the retention time during creation, even if theversion_retention_period
is set in the Terraform configuration. When a plan is generated a 2nd time from the Terraform configuration it will plan to update the retention time on the Postgres DB.This might be confusing to practitioners, but seems like the need to re-apply plans for Postgres databases isn't new and is mentioned in the docs.Edit 2022-06-27 : By separating all execution of DDL into an API call separate to the initial
create
API call this means Postgres's limitations in Spanner don't require 2nd apply stepsOpen questions
version_retention_period
being set before making the Postgres DB be better? That would avoid the confusion of needing to apply a plan twice to reach the desired goalALTER
statement in theddl
parameter of the Terraform provider? The only issue would be if someone addedversion_retention_period
to their config but then resumed setting it viaddl
(version_retention_period
would always re-assert itself on the next plan&apply)PR steps
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)
Derived from GoogleCloudPlatform/magic-modules#6141