<p>We have the below directory structure on the Linux system.</p>
<pre><code> /root
   ├─dirA
   │  ├─main.tf
   │  ├─terraform.tfvars
   │  └─variables.tf
   └─dirB
      └─main.tf
</code></pre>
<p><strong>==FIRST==</strong></p>
<p>We used the below snippet in <code>main.tf</code> file of <code>dirA</code> to create a local kubeconfig file.</p>
<pre><code>resource &quot;local_file&quot; &quot;kubeconfig&quot; {
  content  = module.gke_auth.kubeconfig_raw
  filename = &quot;./kubeconfig&quot;
}
</code></pre>
<p>Now we would like to access this <code>kubeconfig</code> file in the <code>main.tf</code> file of <code>dirB</code> inside the following snippet. Please suggest how to do that?</p>
<pre><code>provider &quot;kubernetes&quot; {
  config_path    = &quot;&lt;PATH_TO_KUBECONFIG_FILE&gt;&quot;
}
</code></pre>
<p><strong>==SECOND==</strong></p>
<p>We have defined some variables inside the <code>terraform.tfvars</code> file of <code>dirA</code> and we would like to access those variables inside the <code>main.tf</code> file of <code>dirB</code>. Please suggest how to do this.</p>

<p>We have solved both the issues with the setup below.</p>
<p>File <strong>dirA/main.tf</strong> contains something similar to</p>
<pre><code>resource &quot;local_file&quot; &quot;kubeconfig&quot; {
  content  = module.gke_auth.kubeconfig_raw
  filename = &quot;${path.module}/kubeconfig&quot;
}

output &quot;kubeconfig_file&quot; {
  value = &quot;${path.cwd}/kubeconfig&quot;
}
</code></pre>
<p>File <strong>dirB/main.tf</strong> contains something similar to</p>
<pre><code>data &quot;terraform_remote_state&quot; &quot;kubeconfig_file&quot; {
  backend = &quot;local&quot;

  config = {
    path = &quot;${path.module}/../dirA/terraform.tfstate&quot;
  }
}

provider &quot;kubernetes&quot; {
  config_path = &quot;${data.terraform_remote_state.kubeconfig_file.outputs.kubeconfig_file}&quot;
}
</code></pre>
<p>Finally:</p>
<pre><code>cd dirA
terraform apply
cd ../dirB
terraform apply
</code></pre>
<p><em>Note: In a similar way we can access variables from the stack in the different directory</em></p>
