<p>I'm currently working on an fully managed by Terraform environment but I reached some limitations and I would like to know if there is a feature or a workaround to do what I want :</p>

<p>I have an environment described like that :</p>

<ul>
<li>A VPC with public and private subnets</li>
<li>An EKS cluster with some workers</li>
<li>Some kubernetes configurations (using the kubernetes provider)</li>
<li>Some helm configurations (using the helm provider)</li>
</ul>

<p>Everything work, but when I want to do a full clean up by running <code>terraform destroy</code> I have to destroy some resources one by one with <code>-target</code> option and then delete manually some references in the state file.</p>

<p>Two reasons why I would like to do that:</p>

<ol>
<li><p><em>Just because it fails</em></p>

<p>Don't know why, but I was unable to destroy with Terraform and manually some subnets (imposible to detach the internet gateway) but I was able to destroy them by simply destroying the VPC.</p>

<p>In this case, I would like to tell to Terraform to only delete the VPC, by doing that, AWS automatically destroy related components such as Subnets, Internet Gateway, Route table, Networks ACL, etc.</p></li>
<li><p><em>Because it would be faster</em></p>

<p>I'm using Terraform with Kubernetes (and Helm) provider to define my Kubernetes configuration, but when I run <code>terraform destroy</code> it will delete all the Kubernetes resources, then the Cluster (and workers).</p>

<p>Only deleting the Cluster would be really faster.</p></li>
</ol>

<hr>

<p>So here is my question :
<strong>Is it possible to exclude resources to the destroy process in the Terraform configuration files ?</strong></p>

Martin Paucot
<p>This allows you to create a plan that destroys all resources except the module &quot;module.exclude.me&quot;</p>
<pre><code>terraform plan -destroy $(for r in `terraform state list | fgrep -v module.exclude.me` ; do printf &quot; -target ${r} &quot;; done) -out destroy.plan
</code></pre>
<p>Credits go to cmacrae from the corresponding github issue:<a href="https://github.com/hashicorp/terraform/issues/2253" rel="nofollow noreferrer">https://github.com/hashicorp/terraform/issues/2253</a></p>
