<p>I have 2 directories:</p>

<ul>
<li><code>aws/</code></li>
<li><code>k8s/</code></li>
</ul>

<p>In the <code>aws/</code> dir, I've provisioned an EKS cluster and EKS node group (among other things) using the Terraform AWS provider. That's been applied and everything looks good there.</p>

<p>When trying to then create a Kubernetes provider plan in <code>k8s/</code> and create a Persistent Volume resource it requires the EBS volume ID. </p>

<p><a href="https://www.terraform.io/docs/providers/kubernetes/r/persistent_volume.html" rel="nofollow noreferrer">Terraform Kubernetes Persistent Volume Resource</a></p>

<p>How do I get the EBS volume ID from the other <code>.tfstate</code> file from a Kubernetes provider plan?</p>

Taylor Turner
<p>So as I understand it, you want to reference resource from another state file. To do that you can use the following example:</p>

<pre><code>data "terraform_remote_state" "aws_state" {
  backend = "remote"

  config = {
  organization = "hashicorp"
  workspaces = {
    name = "state-name"
  }
}
</code></pre>

<p>}</p>

<p>And once you have data resources available you can reference ebs volume in the following way:</p>

<pre><code>data.terraform_remote_state.aws_state.outputs.ebs_volume_id
</code></pre>

<p>Remember to create an output called <code>ebs_volume_id</code></p>
