<p>So I created EKS Cluster using example given in<br />
<a href="https://github.com/cloudposse/terraform-aws-eks-cluster/tree/master/examples/complete" rel="nofollow noreferrer">Cloudposse eks terraform module</a></p>
<p>On top of this, I created AWS S3 and Dynamodb for storing state file and lock file respectively and added the same in <a href="https://www.terraform.io/docs/language/settings/backends/s3.html" rel="nofollow noreferrer">terraform backend config</a>.</p>
<p>This is how it looks :</p>
<pre><code>resource &quot;aws_s3_bucket&quot; &quot;terraform_state&quot; {
  bucket = &quot;${var.namespace}-${var.name}-terraform-state&quot;
  # Enable versioning so we can see the full revision history of our
  # state files
  versioning {
    enabled = true
  }
  # Enable server-side encryption by default
  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        sse_algorithm = &quot;aws:kms&quot;
      }
    }
  }
}

resource &quot;aws_dynamodb_table&quot; &quot;terraform_locks&quot; {
  name         = &quot;${var.namespace}-${var.name}-running-locks&quot;
  billing_mode = &quot;PAY_PER_REQUEST&quot;
  hash_key     = &quot;LockID&quot;
  attribute {
    name = &quot;LockID&quot;
    type = &quot;S&quot;
  }
}

terraform {
  backend &quot;s3&quot; {
    bucket = &quot;${var.namespace}-${var.name}-terraform-state&quot;
    key    = &quot;${var.stage}/terraform.tfstate&quot;
    region = var.region
    # Replace this with your DynamoDB table name!
    dynamodb_table = &quot;${var.namespace}-${var.name}-running-locks&quot;
    encrypt        = true
  }
}
</code></pre>
<p>Now when I try to delete EKS cluster using <code>terraform destroy</code> I get this error:</p>
<pre><code>Error: error deleting S3 Bucket (abc-eks-terraform-state): BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
</code></pre>
<p>This is the output of <code>terraform plan -destroy</code> after the cluster is partially destroyed because of s3 error</p>
<pre><code>Changes to Outputs:
  - dynamodb_table_name             = &quot;abc-eks-running-locks&quot; -&gt; null
  - eks_cluster_security_group_name = &quot;abc-staging-eks-cluster&quot; -&gt; null
  - eks_cluster_version             = &quot;1.19&quot; -&gt; null
  - eks_node_group_role_name        = &quot;abc-staging-eks-workers&quot; -&gt; null
  - private_subnet_cidrs            = [
      - &quot;172.16.0.0/19&quot;,
      - &quot;172.16.32.0/19&quot;,
    ] -&gt; null
  - public_subnet_cidrs             = [
      - &quot;172.16.96.0/19&quot;,
      - &quot;172.16.128.0/19&quot;,
    ] -&gt; null
  - s3_bucket_arn                   = &quot;arn:aws:s3:::abc-eks-terraform-state&quot; -&gt; null
  - vpc_cidr                        = &quot;172.16.0.0/16&quot; -&gt; null
</code></pre>
<p>I cannot manually delete the tfstate in s3 because that'll make terraform recreate everything, also I tried to remove s3 resource from tfstate but it gives me lock error(also tried to forcefully remove lock and with -lock=false)</p>
<p>So I wanted to know is there a way to tell terraform to delete s3 at the end once everything is deleted. Or is there a way to use the terraform which is there in s3 locally?</p>
<p>What's the correct approach to delete EKS cluster when your TF state resides in s3 backend and you have created s3 and dynamodb using same terraform.</p>

<p>Generally, it is not recommended to keep your S3 bucket that you use for Terraform's backend state management in the Terraform state itself (for this exact reason). I've seen this explicitly stated in Terraform documentation, but I've been unable to find it in a quick search.</p>
<p>What I would do to solve this issue:</p>
<ol>
<li><a href="https://www.terraform.io/docs/cli/commands/force-unlock.html" rel="nofollow noreferrer">Force unlock</a> the Terraform lock (<code>terraform force-unlock LOCK_ID</code>, where <code>LOCK_ID</code> is shown in the error message it gives you when you try to run a command).</li>
<li>Download the state file from S3 (via the AWS console or CLI).</li>
<li>Create a new S3 bucket (manually, not in Terraform).</li>
<li>Manually upload the state file to the new bucket.</li>
<li>Modify your Terraform backend config to use the new bucket.</li>
<li>Empty the old S3 bucket (via the AWS console or CLI).</li>
<li>Re-run Terraform and allow it to delete the old S3 bucket.</li>
</ol>
<p>Since it's still using the same old state file (just from a different bucket now), it won't re-create everything, and you'll be able to decouple your TF state bucket/file from other resources.</p>
<p>If, for whatever reason, Terraform refuses to force-unlock, you can go into the DynamoDB table via the AWS console and delete the lock manually.</p>
