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

Retain resources on destroy #1615

Open
JonathanManass opened this issue May 6, 2024 · 4 comments
Open

Retain resources on destroy #1615

JonathanManass opened this issue May 6, 2024 · 4 comments
Labels
accepted This issue has been accepted for implementation. enhancement New feature or request needs-rfc This issue needs an RFC prior to being accepted or, if it's accepted, prior to being implemented.

Comments

@JonathanManass
Copy link

OpenTofu Version

OpenTofu v1.7.0

Use Cases

When creating certain resources that we need to keep when deleting the environment, I don't want to do any manual actions.

There are certain resources, such as buckets or log groups, that especially for production environments, need to be kept for several months after the deletion of an environment.

Attempted Solutions

Currently the only way to do this is to remove it from the state manually or to comment the resource and add a removed block which is not better.

Proposal

My proposal is the same as that of my references below, just for a different use case.

This means adding another keyword to the lifecycle block that will either work alongside prevent_destroy or replace it.

  1. Encapsulating all inside one keyword

lifecycle {
on_destroy = <destroy|prevent|retain|(ignore)>
}

With destroy being the default behaviour (could be that this is unnecessary except for the case where this can be made dynamic)
Prevent being the prevent_destroy = true curent behaviour
Retain meaning that the resource is removed from the state but the actual destroy operation is not sent to the provider

You could even imagine an additional ignore operation which would be similar to retain and would also leave the resource in the state

  1. Adding a new one for the specific use case

lifecycle {
retain_on_destroy = <true|false>
}

which would be the same as the Retain from the first proposal (the resource is removed from the state but the actual destroy operation is not sent to the provider).

References

@JonathanManass JonathanManass added enhancement New feature or request pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels May 6, 2024
@janosdebugs
Copy link
Contributor

Hello and thank you for this issue! The core team regularly reviews new issues and discusses them, but this can take a little time. Please bear with us while we get to your issue. If you're interested, the contribution guide has a section about the decision-making process.

@Evi1Pumpkin
Copy link
Collaborator

Hi @JonathanManass.
Thanks for opening this issue.
Can you please explain your use case and why you don't want to use the removed block solution?

@JonathanManass
Copy link
Author

JonathanManass commented May 7, 2024

Hi @Evi1Pumpkin.

If I understand the removed block correctly, the aim is to use it when removing resources from the terraform configuration, so replacing a resource block by a removed block before applying.

The way I use opentofu is to have one workspace per customer environment.
This results in many different workspaces that all have similar configurations.
If I were to destroy one environment, I would want to preserve certain resources such as the bucket and logs.
However, the other workspaces should not be touched in that process and ideally this would not require any manual action, such as removing the resource and adding the removed bloc, running the destroy, and rolling this back after that.

With this solution, I could just run the destroy without any manual action to be taken beforehand, and know my resource will not be deleted.

@cam72cam cam72cam added accepted This issue has been accepted for implementation. needs-rfc This issue needs an RFC prior to being accepted or, if it's accepted, prior to being implemented. and removed pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels May 9, 2024
@Evi1Pumpkin
Copy link
Collaborator

Hi @JonathanManass,
The core team thinks this suggestion is good and believes we should implement your first proposition.
We don't need a new ignore operation. We can use the forget action we added for the removed block.
We still need to understand how this will technically work, and how it'll co-exist with the current prevent_destroy option, that's why we need an RFC first before we start implementing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has been accepted for implementation. enhancement New feature or request needs-rfc This issue needs an RFC prior to being accepted or, if it's accepted, prior to being implemented.
Projects
None yet
Development

No branches or pull requests

4 participants