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

[Feature Request] Add "deleted_by" meta-argument to resource lifecycle #34530

Open
cybershoe opened this issue Jan 16, 2024 · 2 comments
Open
Labels
enhancement new new issue not yet triaged

Comments

@cybershoe
Copy link

Terraform Version

Terraform v1.6.6
on darwin_arm64

Use Cases

With some providers, deleting a resource also deletes subordinate objects associated with that resource (e.g: deleting a resource group deletes its contents, deleting an NGINXaaS for Azure deployment deletes its configurations and certificates, etc.). Where that behaviour is expected, a user should be able to specify in a resource's lifecycle block that deleting a related resource will also delete the subordinate resource; in that case terraform destroy should not explicitly delete the subordinate resource if it is already planning on deleting the parent resource.

There are two main benefits to this approach:

  1. The destroy process is simplified. The resource provider presumably has a better understanding of the best order of operations to delete its subordinate resources. So long as the user is confident that the provider will properly perform the deletion, the implementation details should be left to the provider.

  2. For providers with a less-than-perfect API success rate, this reduces the number of API calls, and therefore the chances of a failure preventing the destroy operation from succeeding.

Attempted Solutions

Currently, to prevent removal of a resource, I must delete it from the terraform state with terraform state rm. This works, but it is an extra imperative step that should be handled by terraform's order of operations planning.

Proposal

Add a "deleted_by" meta-parameter to the lifecycle block. The value of this parameter is another resource that, when deleted, will also destroy the resource in question. When terraform destroy is run, terraform will not explicitly destroy the subordinate resource if it is already planning to destroy the parent resource.

This should be an explicit meta-parameter. Terraform may not be able to know in all cases whether a subordinate resource is deleted by a particular parent resource, and in any event this behaviour may not even be desired, so it should be left to the discretion of the user.

References

Implements a use case from:

Relates to:

@cybershoe cybershoe added enhancement new new issue not yet triaged labels Jan 16, 2024
@cybershoe cybershoe changed the title [Feature Request] Add "deleted_by" meta-argument to resource lifecucle [Feature Request] Add "deleted_by" meta-argument to resource lifecycle Jan 16, 2024
@crw
Copy link
Contributor

crw commented Jan 16, 2024

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

@jbardin
Copy link
Member

jbardin commented Jan 22, 2024

Hi @cybershoe,

This is more related to #22094 than the linked issues (and is in fact one of the use cases for that proposal). Adding the reference to the resource block alone doesn't really really help us here, because the resource configuration applies to one or more instances, and the reference can't describe the relationships between the individual instances.

More declarative configuration in this area is also being explored via the new removed block, but this particular type of relationship may not turn out to be handled due to not being able to clearly map out how the resource instances between resources are related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants