-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add ability to preserve local_file on destroy #7
Comments
Hi @alanbchristie! Thanks for this feature request and sorry for the delay in responding to it. The Terraform team at HashiCorp won't be able to work on this in the near future due to our focus being elsewhere, but we'd be happy to review a pull request if you or someone else has the time and motivation to implement it. There is some precedent for options like this for resources where it's common to use Terraform to create them but to pass management onto some other system after a while. Usually these have names like (The reason for the |
This change introduces the `preserve_on_destroy` option for the local_file resource. This defaults to `false`, but when set to `true` will ensure that the file is preserved when the resource is destroyed in Terraform. Resolves: hashicorp#7
@apparentlymart I have attempted a resolution in #10, happy to take any feedback. |
Hello, |
This change introduces the `preserve_on_destroy` option for the local_file resource. This defaults to `false`, but when set to `true` will ensure that the file is preserved when the resource is destroyed in Terraform. Resolves: hashicorp#7
Thanks for your patience @abn while we improve our triage process for the HashiCorp providers. I'd like to understand more about your use case here: since you are calling |
@kmoe To be honest, my memory of the original use case is a bit shoddy. But, as the description says, the particular case that lead to this was since we created a few resources on AWS that generated tokens and/or configurations that needed to be used to in order to clean up resources that were created post-apply outside of tf state, which needed to be cleaned up using an ansible playbook after destroy was called. The simple requirement is to be able to not delete a generated file; there are various other cases where this will come in handy in general. |
same here |
still the same needed here |
I'd love to say I'm still interested in this problem, but I'm not. Instead, as indicated at the start of the issue, I use Ansible as a controller so I just copy the file out of Terraform's way once the infrastructure's provisioned. Then, after I call destroy, when control switches back to my Ansible playbook, I have the file prior to its deletion and can do the required processing. With regard to the earlier question in 2020 why anyone would want to keep such a file? Unlike other resources the fact it's a "local" resource should hint that it's typically does not play a crucial role within the infrastructure ... it's "local" after all (and would get re-written anyway when you run Anyway - it's been more productive for me to code around the behaviour using an external tool. |
This change introduces the `preserve_on_destroy` option for the local_file resource. This defaults to `false`, but when set to `true` will ensure that the file is preserved when the resource is destroyed in Terraform. Resolves: hashicorp#7
+1 to have a non-destructive action to file when |
This option is similar to having a prevent_destroy meta-argument but without causing terraform to fail. It is indeed a good feature to have. |
I need to execute script when all environment destroy. It will be great to have this features. |
I do agree that this would be a good feature to have. I'm facing some problems in my solution due to the lack of this feature |
This issue was originally opened by @alanbchristie as hashicorp/terraform#17040. It was migrated here as a result of the provider split. The original body of the issue is below.
Would it be possible to add a
do_not_destroy
argument to thelocal_file
configuration item so that whenterraform destroy
is executed the generated local file is left intact? The reason? I create dynamic content for a post-destroy Ansible script and it would be useful to keep the content of the locally-generated file for this playbook.i.e. would it be acceptable to provide the ability to do this...
With the above if
terraform apply
is re-excuted is is perfectly fine (and expected) to over-write any existing file.Terraform Version
Terraform Configuration Files
Debug Output
n/a
Crash Output
n/a
Expected Behavior
n/a
Actual Behavior
n/a
Steps to Reproduce
n/a
Additional Context
n/a
References
n/a
The text was updated successfully, but these errors were encountered: