<p>I have 3 applications in separate directories handled with the kubernetes manifest files.</p>
<p>And I want to use terraform to deploy all the applications in different directories.</p>
<p>The structure of the applications show below.</p>
<pre><code>app-1
  L kubernetes_manifest
    L deployment.yaml. ## use Dockerfile to run the app 
  L app
    L app.py
  Dockerfile. ## wrap the app
app-2
  L kubernetes_manifest
    L deployment.yaml. ## use Dockerfile to run the app 
  L app
    L app.py
  Dockerfile. ## wrap the app
app-3
  L kubernetes_manifest
    L deployment.yaml. ## use Dockerfile to run the app 
  L app
    L app.py
  Dockerfile. ## wrap the app
app_terraform
   L main.tf
</code></pre>
<p>main.tf</p>
<pre><code>resource &quot;google_container_cluster&quot; &quot;test_cluster&quot; {
  project = &quot;test&quot;
  name     = &quot;test-cluster&quot;
  initial_node_count       = 1
}
</code></pre>
<p>Is there a way to deploy all the applications in <code>main.tf</code>?</p>

Eric Lee
<p>I maintain the <a href="https://registry.terraform.io/providers/kbst/kustomization/latest" rel="nofollow noreferrer">Kustomization Provider</a> which allows you to use native Kubernetes YAML in Terraform.</p>
<p>You can either use the provider directly or use a convenience module I additionally provide. I maintain both as part of my <a href="https://www.kubestack.com/" rel="nofollow noreferrer">Terraform framework for AKS, EKS and GKE</a>.</p>
<p>The module approach may be more convenient, because then you can simply call the module once per app and have a good balance between maintainable code and no unnecessary coupling between the apps. The module also handles the <a href="https://registry.terraform.io/providers/kbst/kustomization/latest/docs/resources/resource#terraform-limitation" rel="nofollow noreferrer">ids_prio approach</a>, which is more robust for larger numbers of K8s resources, out of the box.</p>
<h1>Option 1: Provider</h1>
<p><code>app-1.tf</code>:</p>
<pre><code>data &quot;kustomization_overlay&quot; &quot;app_1&quot; {
  resources = [
    &quot;${path.root}/app-1/kubernetes_manifest/deployment.yaml&quot;
  ]
}

resource &quot;kustomization_resource&quot; &quot;test&quot; {
  for_each = data.kustomization_build.app_1.ids

  manifest = data.kustomization_build.app_1.manifests[each.value]
}

</code></pre>
<h1>Option 2: Module</h1>
<p><code>app-1.tf</code>:</p>
<pre><code>module &quot;app_1&quot; {
  source  = &quot;kbst.xyz/catalog/custom-manifests/kustomization&quot;
  version = &quot;0.1.0&quot;

  configuration_base_key = &quot;default&quot;
  configuration = {
    default = {
      resources = [
        &quot;${path.root}/app-1/kubernetes_manifest/deployment.yaml&quot;
      ]
    }
  }
}
</code></pre>
