-
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
Allow deletion of resource_bigquery_table when it still has associated resource tags #10568
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2f1507
allow deletion of resource_bigquery_table when it still has associate…
wj-chen 1409171
add a virtual field allow_resource_tags_on_deletion
wj-chen 19a5db6
add new field to unit test config
wj-chen e30d3db
fix indentation
wj-chen 49351c2
add version guard to import logic
wj-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1157,6 +1157,15 @@ func ResourceBigQueryTable() *schema.Resource { | |
Description: `Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail.`, | ||
}, | ||
|
||
<% unless version == 'ga' -%> | ||
"allow_resource_tags_on_deletion": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: `Whether or not to allow table deletion when there are still resource tags attached.`, | ||
}, | ||
|
||
<% end -%> | ||
// TableConstraints: [Optional] Defines the primary key and foreign keys. | ||
"table_constraints": { | ||
Type: schema.TypeList, | ||
|
@@ -1834,13 +1843,15 @@ func resourceBigQueryTableDelete(d *schema.ResourceData, meta interface{}) error | |
} | ||
<% unless version == 'ga' -%> | ||
if v, ok := d.GetOk("resource_tags"); ok { | ||
var resourceTags []string | ||
if !d.Get("allow_resource_tags_on_deletion").(bool) { | ||
var resourceTags []string | ||
|
||
for k, v := range v.(map[string]interface{}) { | ||
resourceTags = append(resourceTags, fmt.Sprintf("%s:%s", k, v.(string))) | ||
} | ||
for k, v := range v.(map[string]interface{}) { | ||
resourceTags = append(resourceTags, fmt.Sprintf("%s:%s", k, v.(string))) | ||
} | ||
|
||
return fmt.Errorf("cannot destroy table %v without clearing the following resource tags: %v", d.Id(), resourceTags) | ||
return fmt.Errorf("cannot destroy table %v without unsetting the following resource tags or setting allow_resource_tags_on_deletion=true: %v", d.Id(), resourceTags) | ||
} | ||
} | ||
|
||
<% end -%> | ||
|
@@ -2675,6 +2686,11 @@ func resourceBigQueryTableImport(d *schema.ResourceData, meta interface{}) ([]*s | |
if err := d.Set("deletion_protection", true); err != nil { | ||
return nil, fmt.Errorf("Error setting deletion_protection: %s", err) | ||
} | ||
<% unless version == 'ga' -%> | ||
if err := d.Set("allow_resource_tags_on_deletion", false); err != nil { | ||
return nil, fmt.Errorf("Error setting allow_resource_tags_on_deletion: %s", err) | ||
} | ||
Comment on lines
+2690
to
+2692
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may also need to mark it as beta only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
<% end -%> | ||
|
||
// Replace import id for the resource id | ||
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/datasets/{{dataset_id}}/tables/{{table_id}}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 think this is a breaking change that should be avoided a minor release. This is
Changing resource deletion behavior
in https://googlecloudplatform.github.io/magic-modules/develop/breaking-changes/breaking-changes/#resource-level-breaking-changes.We have a couple of options:
Please let me know your thoughts and if you have any questions. Thanks!
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.
Would the combination of the points below make it eligible for a minor version release?
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.
@wj-chen Thanks for the quick response.
The beta provider is also a stable surface that does not allow breaking changes outside of major releases. See go/terraform-launch-stages#google-beta
I'd still think it's breaking since it's changing the default deletion behavior and I'm a bit hesitant about changing it directly in a minor. However, if an urgent fix is needed in a minor, we could follow https://googlecloudplatform.github.io/magic-modules/develop/breaking-changes/make-a-breaking-change/#in-minor-releases - "this change can be made if the default behavior stays the same and new behavior can be enabled with a flag", such as adding a
force_delete
field, which is the option 2 I proposed in #10568 (comment). Please let me know what your thought on this approach and if it will work for your use case. Thanks!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 added a virtual field
allow_resource_tags_on_deletion
for this purpose and this PR is ready for review again.Can you also describe the migration path from this to my original change? Would that be a candidate for the next major release?
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.
Will discuss internally regarding the migration path for the next major release
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.
Hi @shuyama1, I'd like to follow up on this discussion again since the submission window for the next major release is now open. We want to promote this field to the GA provider, and make the default value
true
in the GA provider from the get-go if possible.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.
@wj-chen Thank you for following up on this issue.
Our policy requires that the beta provider be a superset of the GA provider. This means the features and behaviors in GA should always be consistent with those in beta.
If we want to promote the feature to GA before changing the default in beta in 6.0.0 (as you correctly noted, this default value swap is a breaking change and must wait until the 6.0.0 major release), we need to use the current default value and update the default values for both GA and beta later in the 6.0.0 release.
Hope this answers your question and let me know if you have further questions.
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 this case we'll proceed with promoting the feature to GA first, then making a breaking change to change the default value for the field for both GA and beta providers in the 6.0.0 release. Thank you for the guidance!
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.
Perfect. Sounds good!