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 support pitr restore to sql #6862

Conversation

doriandekoning
Copy link

Still work in progress but this add support for creating a sql instance as a clone from another instance at a given point in time. https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/clone

#6848

I still have to write the tests for this, but I've pushed it to verify the direction I'm taking with this feature is the right one.

@nat-henderson
Copy link
Contributor

Okay, cool. What's your plan for dealing with the other required fields? Are you imagining leaving them as required and forcing the user to set them to valid values? And what are you planning for post-create drift for the clone field?

@doriandekoning
Copy link
Author

Leaving them required would indeed not be an ideal solution, I assume it might be possible to use the RequiredWith field in some way to ensure the user does not have to set them? On the other hand, having the user provide valid values is quite similar to the behaviour when creating a replica of an instance currently (the replica also has to have some of the fields the same values as the master I believe). However, this might require us to validate the values ourselves since the google api will not do this when cloning an instance.

As for the drift, I'm not quite sure about a good way to handle that. I might have to take a look at how it is handled in other resources/providers or do you have an idea/know of a standardised way of handling this?

I'll take a closer look at this tomorrow.

@nat-henderson
Copy link
Contributor

We don't have a standard answer to these questions - normally we would probably just leave this in the backlog because we can't think of a good answer to them! If you can, that will be neat. The crucial guiding factors should be

a) does not significantly change the experience for non-users of this feature
b) provides clear expectations for how to use this feature.

@doriandekoning
Copy link
Author

What I think we can do to solve both those problems (partially) in this case is the following.
For the database resource, afaik only the settings argument is currently required. Therefore we can add an AtleastOneOf for settings/clone. This results in three cases for creation:

  • Clone is not set, we do the usual for creation
  • Clone is set but settings argument isn't, we create the instance using the clone route of the API
  • Both clone and settings are set, in this case, we first create the instance using the clone route and after this call the update route to make it consistent with the settings.

In this case a) the experience is not changed for non-users, apart from some additional lines in the docs explaining the Atleastoneof and b) it should be pretty easy to explain the AtleastOneOf constraint in the docs and mention that the clone configuration is only used during creation, similar to the other settings I believe (according to this comment in the update function "// Update only updates the settings... ).

With this approach, there is a slight configuration drift in the clone field (it will only be used during creation, and not be set during import), but this also seems to be the case for some of the other arguments.

I've implemented this and it seems to work, unfortunately, I haven't had time to write any tests for it yet.

@nat-henderson
Copy link
Contributor

Great! I'm comfortable with that as the best possible outcome. One test case for each of the three cases would prove it to me, let me know when you're ready for a review!

@ghost ghost added size/m and removed size/s labels Aug 2, 2020
@doriandekoning
Copy link
Author

I'm sorry for the delay. I've manually tested all three cases by enabling the pitr for the source instance manually.
To be able to write proper tests I think it would be best to wait a bit for #6715 to be finished. The restore feature won't be very useful without it anyway.

@doriandekoning doriandekoning force-pushed the add-sql-pitr-restore-support branch 2 times, most recently from 9ad1c3b to 8a48c7c Compare August 2, 2020 14:56
@nat-henderson
Copy link
Contributor

Great, it looks like that will be going in today! Let me know when you're ready for review, your approach seems good to me.

@doriandekoning
Copy link
Author

doriandekoning commented Aug 9, 2020

Quick update. I have some trouble with the automatic tests because a backup first has to be created to be able to create a clone but the Manual backup trigger option does not seem to work (aka probably works different then I expect it to work). I have limited time but I hope to finish it tomorrow or Tuesday night.

@nat-henderson
Copy link
Contributor

Great, thanks for your help!

@poj89
Copy link

poj89 commented Mar 2, 2022

Hello, is there any progress to this request? We have a use case where our users only read-only access to Google Cloud Console and would need to be able to execute point-in-time-recovery by supplying the timestamp or backup ID using Terraform. Can this be done using Magic Modules?

@doriandekoning
Copy link
Author

@poj89 It was added in another MR, it was added as: point_in_time_recovery_enabled

@poj89
Copy link

poj89 commented Mar 3, 2022 via email

@doriandekoning
Copy link
Author

Hi @poj89, I'm afraid I can't really help you out with these questions. I'm also just a user of the provider.

I believe we just use the point_in_time together with the source_instance_name parameter. I think there is a way to list the existing backups using the datasource [sql_backup_run].(https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/sql_backup_run) but I have no experience with it.

I hope someone else is able to answer your question!

@github-actions
Copy link

github-actions bot commented Apr 7, 2022

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants