Set resource to last destroy

I have a datasource which outputs the kubeconfig.yaml of a cluster. This file is used to set the helm provider kubernetes config_path.
When I apply a destroy, the file is one of the first to be destroyed. Destroying result in failure on a later step as the kubeconfig is missing.
How to make `resource “local_file” “kubeconfig” the last item to be destroyed ?

The only way I can think of achieving this would be to manually declare a depends_on in every single Helm resource, specifying a dependency on the local file resource.

That’s quite ugly though.

I think you’d be better off moving the environment setup outside of Terraform - it’s not architected to support parts of one Terraform configuration setting things up which are required by other providers in the same configuration.

Thanks for clarifying. I may want to live with depends_on for the moment.

Hi @wmsan,

Can you show an example of the configuration you are using? You mention that the input for the provider is a data source, but you are also using a local_file managed resource in some way.

If I were to guess, you have multiple layers of resources that you are attempting to create and destroy within a single configuration. When you have a provider which depends on the result of other managed resources, that needs to be managed by separate configurations, i.e. one configuration would build the infrastructure to run kubernetes, and another configuration would build kubernetes itself.

I kind of found ways to destroy that resource on a later step, but I properly solve the issue by not using it as a dependency to my providers, instead just a handy option.

Your comment helped me to create a better picture of how things work with terraform. thanks.