<p>I've been using terraform for a while now and I have deployed everything into separate clusters. Now due to cost, we'd like to merge the different clusters into one cluster and use kubernetes namespaces.</p>
<p>My desired outcome would be that I could call <code>terraform apply - var=&quot;kubernetes_namespace=my-namespace&quot;</code> and it would create the namespace which could live alongside my other namespaces, however, due to how terraform remote state is managed, any new deployment will overwrite the old and I can't have co-existing namespaces.</p>
<p>When I try to redeploy another namespace I get
<code>namespace        = &quot;deploy-pr-image&quot; -&gt; &quot;test-second-branch-pr&quot; # forces replacement</code></p>
<p>I can see why because it's writing everything to a single workspace file.</p>
<pre><code>terraform {
  backend &quot;s3&quot; {
    bucket               = &quot;my-tf-state&quot;
    key                  = &quot;terraform-services.tfstate&quot;
    region               = &quot;us-west-1&quot;
    workspace_key_prefix = &quot;workspaces&quot;
    #dynamodb_table       = &quot;terraform-state-lock-dynamo&quot;
  }
}
</code></pre>
<p>Is there some way to use the workspace/namespace combination to keep terraform from overwriting my other namespace ?</p>

jdkealy
<p>Since now you'll be merging all your clusters into a single one, it would make sense to only have a backend where you can manage the state of the cluster rather than having multiple backends per Kubernetes namespaces.</p>
<p>I suggest you to update your module or root deployment to be flexible enough that it can create X number of Kubernetes namespaces resources rather than a single one using <code>count</code> or <code>for_each</code>.</p>
