<p>I need to create GKE cluster and then create namespace and install db through helm to that namespace. Now I have gke-cluster.tf that creates cluster with node pool and helm.tf, that has kubernetes provider and helm_release resource. It first creates cluster, but then tries to install db but namespace doesn't exist yet, so I have to run <code>terraform apply</code> again and it works. I want to avoid scenario with multiple folder and run <code>terraform apply</code> only once. What's the good practice for situaction like this? Thanks for the answers.</p>

Jozef Vrana
<p>The <code>create_namespace</code> argument of <code>helm_release</code> resource can help you.</p>
<pre><code>create_namespace - (Optional) Create the namespace if it does not yet exist. Defaults to false.
</code></pre>
<p><a href="https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#create_namespace" rel="noreferrer">https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release#create_namespace</a></p>
<p>Alternatively, you can define a dependency between the <code>namespace</code> resource and <code>helm_release</code> like below:</p>
<pre><code>resource &quot;kubernetes_namespace&quot; &quot;prod&quot; {
  metadata {
    annotations = {
      name = &quot;prod-namespace&quot;
    }

    labels = {
      namespace = &quot;prod&quot;
    }

    name = &quot;prod&quot;
  }
}
</code></pre>
<pre><code>resource &quot;helm_release&quot; &quot;arango-crd&quot; { 
  name = &quot;arango-crd&quot; 
  chart = &quot;./kube-arangodb-crd&quot;
  namespace = &quot;prod&quot;  

  depends_on = [ kubernetes_namespace.prod ]
}
</code></pre>
