-
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 restoreBackup support for sql db instance #4336
Add restoreBackup support for sql db instance #4336
Conversation
@@ -1025,6 +1056,8 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) | |||
return err | |||
} | |||
|
|||
// TODO if d.HasChange("settings") doesn't work, so we just send an empty request if only restoring from backup |
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.
Thanks to hashicorp/terraform-plugin-sdk#98 and settings.authorized_networks
, d.HasChange("settings") always returns true.
As it stands the resource will send empty updates which causes an extra harmless request.
I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=164108" |
@@ -1051,6 +1084,15 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) | |||
return err | |||
} | |||
|
|||
if r, ok := d.GetOk("restore_backup_context"); ok { |
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.
To support restoring from a backup during Update, we'll have to trigger when changes are made to restore_backup_context
other than the field just being removed
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.
Can you comment that inline?
The draft is still pending: Tests showcasing create + update restoreBackup triggers |
I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=164108" |
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 seems like a reasonable take. We'll want to be explicit in the documentation that this is a pretty dangerous field to set & document how it may behave differently than other fields.
Test capability is pending #4352 for datasource use and backup bootstrapping |
45fe6bf
to
1a953a1
Compare
I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=165413" |
I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccDataSourceGoogleSubnetwork|TestAccDataSourceStorageBucketObjectContent_Basic|TestAccActiveDirectoryDomainTrust_activeDirectoryDomainTrustBasicExample|TestAccContainerCluster_withConfidentialNodes|TestAccContainerCluster_withPrivateClusterConfigMissingCidrBlock|TestAccDataprocJob_Spark You can view the result here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=165417" |
@@ -1051,6 +1084,15 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) | |||
return err | |||
} | |||
|
|||
if r, ok := d.GetOk("restore_backup_context"); ok { |
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.
Can you comment that inline?
Required: true, | ||
Description: `The ID of the backup run to restore from.`, | ||
}, | ||
"instance_id": { |
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.
Just curious: what does specifying this field (or not specifying this field) change?
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.
You can optionally restore to the backup of another instance (backup ID's are unique per instance). If left blank, the API just assumes the same instance. I can add a line in the documentation to make this more clear.
I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=165856" |
I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccInstanceTemplateDatasource_name|TestAccInstanceTemplateDatasource_filter|TestAccInstanceTemplateDatasource_filter_mostRecent|TestAccDataSourceGoogleSubnetwork|TestAccDataSourceGoogleServiceAccountIdToken_impersonation|TestAccDataSourceStorageBucketObjectContent_Basic|TestAccActiveDirectoryDomainTrust_activeDirectoryDomainTrustBasicExample|TestAccContainerCluster_withConfidentialNodes|TestAccContainerCluster_withPrivateClusterConfigMissingCidrBlock|TestAccDataprocJob_Spark You can view the result here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=165864" |
@rileykarson and @c2thorn, I believe this has caused a regression. I was able to trigger it by $ terraform import module.modulename.google_storage_bucket.bucketname bucketname
module.modulename.google_storage_bucket.bucketname: Importing from ID "bucketname"...
module.modulename.google_storage_bucket.bucketname: Import prepared!
Prepared google_storage_bucket for import
module.modulename.google_storage_bucket.bucketname: Refreshing state... [id=bucketname]
Error: Invalid resource instance data in state
on ../modules/sql/main.tf line 19:
19: resource "google_sql_database_instance" "postgres" {
Instance module.sql.google_sql_database_instance.postgres
data could not be decoded from the state: unsupported attribute
"restore_backup_context". This does not happen when I run $ terraform version
Terraform v0.14.5
+ provider registry.terraform.io/hashicorp/aws v3.24.1
+ provider registry.terraform.io/hashicorp/google v3.52.0
+ provider registry.terraform.io/hashicorp/google-beta v3.52.0
+ provider registry.terraform.io/hashicorp/kubernetes v1.13.3
+ provider registry.terraform.io/hashicorp/kubernetes-alpha v0.2.1
+ provider registry.terraform.io/hashicorp/random v3.0.1
+ provider registry.terraform.io/hashicorp/tls v3.0.0 |
Hey @achew22, sorry for any troubles that this may have caused you. I tried reproducing this error myself by importing a storage bucket while already having a database instance in state, but was not able to get the error. Do you mind filing a new issue with the steps you have taken and potentially your terraform configuration that produced this error? |
@c2thorn I would be very happy to do this. Do you have any hints on things that you think might be related to this. This is deep in the bowels of our terraform config and it even took me a while to get the stack trace (not sure what else to call it) cleaned up for publication. I can poke at it, but I'm, unfortunately timeboxed on this one. |
@achew22 I just realized that this feature was released in v3.53 of the providers and your log shows v3.52. This seems like a versioning issue where maybe some part of your config is using a different version ( Maybe you can try constraining 3.53 or newer via https://www.terraform.io/docs/configuration/provider-requirements.html#version-constraints ? |
@c2thorn Sorry to raise the false alarm. I think you're right. I was able to force my local terraform to v3.53 and it seems to be working now. Thanks so much! |
@achew22 Great! Glad you were able to get unstuck! |
Fixes hashicorp/terraform-provider-google#2446
Add support for the very imperative restoreBackup action. This change essentially triggers the restoreBackup action:
restore_backup_context
is setrestore_backup_context
has a changeIf 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)