What I need is terraform analog for CloudFormation's DeletionPolicy: Retain
.
The resource should be left as is during terraform destroy
, that's all.
prevent_destroy
does not fit because the whole environment going to be deleted during terraform destroy
ignore_changes
does not fit because there's no parameter's change.
How can I do it?
The terraform destroy command terminates resources managed by your Terraform project. This command is the inverse of terraform apply in that it terminates all the resources specified in your Terraform state. It does not destroy resources running elsewhere that are not managed by the current Terraform project.
One option here is to tell Terraform to “forget about” this object, which will sever the binding between the object in the remote system and this block in your configuration. The object will continue to exist but Terraform will no longer have any record of it, and so terraform destroy will not propose to delete it.
Currently, there is no way to specify the resources NOT to be destroyed using Terraform.
You could break down the destroy to a set of tasks
terraform state rm
, to remove resources/modules you want to retain, from your state. Now they are no longer tracked by terraform..tf
filesterraform plan
. You should see that there are no changes to be applied. This is to ensure that the selected resources have been safely removed from your terraform state files and terraform code.terraform destroy
. This should destroy all other resources.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With