add support for universal deletion_policy#27311
Merged
modular-magician merged 1 commit intoMay 11, 2026
Merged
Conversation
[upstream:e5b837d81166744565f99310316c189e91a14fae] Signed-off-by: Modular Magician <magic-modules@google.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Universal deletion_policy is a string field added to the top-level schema of all compatible resources. Rather than using a “default” attribute, it is configured as an optional+computed field.
To display a default from provider configuration or resource settings, it is dependent on a new customize diff function that operates in a similar way to the customize diff functions for displaying Project/Region/Zone at plan-time. A GetRawConfig() check is performed on the resource to verify if it has been set explicitly by the user, and in absence of that checks for if a user has configured a value within their provider configuration, and if that is absent it goes with the resource default. There is no fall back state behind this, as all resources have a default supplied to this customize diff function as a string argument.
At the end of the read function some code has been included for setting virtual fields to their default (following standard design for TPG resources), with the minor addition of checking the provider configuration before using the resource default.
If a resource has been excluded from supporting resourceUpdate() previously, it has been updated to have an Update function that immediately returns resourceRead(). Existing update functions have had a PreUpdate check introduced at the beginning, which quickly checks over the resource to verify if any updates have been planned other than those to deletion-policy, and if only deletion_policy is being updated, will short circuit the function into returning resource*Read().
Lastly, a PreDelete check has been added that performs the logic for either “PREVENT” or “ABANDON”. If necessary due to some implementations using different terms (e.g. “DEFAULT” often being used in place of “DELETE” previously), existing implementations have been updated to be compatible with these standard terms.
Supporting the above implementation, three attributes have been added to resource.go for usage in resource yaml files:
deletion_policy_exclude, if set to true this will avoid generating the deletion_policy related fields to the end resource. This is set to true for resources that are incompatible with a deletion policy (such as those with no delete function), or those that had existing, incompatible implementations.
deletion_policy_custom_docs, if set to true this will avoid generating the standard docs description for the universal deletion policy field. This is set to true for resources which support custom options in their deletion_policy such as “force”, and need a bespoke description for their usage. These resources have maintained their virtual field deletion_policy fields, but updated to have an “exclude: true” attribute that will avoid them being generated into the downstream resource (as these resources will use the fully standard field/associated code in most areas, with their custom code generally being contained within a pre_delete constant.
deletion_policy_default, a string attribute that can be set to the desired default value for a resource. This will default to “DELETE” if unset.
One attribute deletion_policy has been added to provider.go and config.go, and is used to enable configuring the provider-level default.
Release Note Template for Downstream PRs (will be copied)
See Write release notes for guidance.
Derived from GoogleCloudPlatform/magic-modules#17380