Skip to content

add support for universal deletion_policy#27311

Merged
modular-magician merged 1 commit into
hashicorp:mainfrom
modular-magician:downstream-pr-e5b837d81166744565f99310316c189e91a14fae
May 11, 2026
Merged

add support for universal deletion_policy#27311
modular-magician merged 1 commit into
hashicorp:mainfrom
modular-magician:downstream-pr-e5b837d81166744565f99310316c189e91a14fae

Conversation

@modular-magician
Copy link
Copy Markdown
Collaborator

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.

provider: support for a `deletion_policy` field has been added to almost all resources in the provider. Details on its usage can be found within individual resource documentation if supported.

Derived from GoogleCloudPlatform/magic-modules#17380

[upstream:e5b837d81166744565f99310316c189e91a14fae]

Signed-off-by: Modular Magician <magic-modules@google.com>
@modular-magician modular-magician merged commit 925434c into hashicorp:main May 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant