<p>You need to pass that info to your module or also declare it in your module again. For example, for the region, pass it as a variable to the module:</p>

<pre><code>module "foo" {
  ...
  current_region = "${data.aws_region.current.name}"
  ...
}
</code></pre>

<p>Or add it inline in your module, just like you did in your <code>main.tf</code></p>

CC BY-SA 4.0
2018-06-14T13:56:52.540Z
I ended up adding it inline to the module and that worked, I've accepted as the answer. Thanks for your help.
Caledonia91
CC BY-SA 4.0
2018-06-14T13:42:18.457Z
2018-06-14T13:42:18.457Z
B. Miller
<p>I'm fairly new to Terraform and have been following this example on creating an EKS cluster - <a href="https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples/eks-getting-started" rel="nofollow noreferrer">https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples/eks-getting-started</a></p>

<p>Only difference is that I've broken the structure up into modules:</p>

<pre><code>-main.tf
-vpc
   vpc.tf
   vars.tf
-eks
   eks-cluster.tf
   eks-worker-nodes.tf
   vars.tf
   outputs.tf
</code></pre>

<p>In 'main.tf' I've got the following</p>

<pre><code>provider "aws" {
  region     = "us-east-1"
}

# Using these data sources allows the configuration to be
# generic for any region.
data "aws_region" "current" {}

data "aws_availability_zones" "available" {}
</code></pre>

<p>When I run a 'terraform plan' I get the following error which comes from eks-worker-nodes.tf :</p>

<pre><code> * module.eks.local.demo-node-userdata: local.demo-node-userdata: 
 Resource 'data.aws_region.current' not found for variable 
'data.aws_region.current.name'       
</code></pre>

<p>Is there any reason why it wouldn't be able to access the data source? I'm fairly new to Terraform but I've done some googling and couldn't find a clear answer :/</p>

<amazon-web-services><kubernetes><terraform>
Terraform Issue - Can't find Data Source in Sub Module?
Caledonia91
# Terraform Issue - Can't find Data Source in Sub Module?

(Asked by: username_0 on 2018-06-14)

I'm fairly new to Terraform and have been following this example on creating an EKS cluster - https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples/eks-getting-started
Only difference is that I've broken the structure up into modules:
-main.tf
-vpc
   vpc.tf
   vars.tf
-eks
   eks-cluster.tf
   eks-worker-nodes.tf
   vars.tf
   outputs.tf

In 'main.tf' I've got the following
provider "aws" {
  region     = "us-east-1"
}

# Using these data sources allows the configuration to be
# generic for any region.
data "aws_region" "current" {}

data "aws_availability_zones" "available" {}

When I run a 'terraform plan' I get the following error which comes from eks-worker-nodes.tf :
 * module.eks.local.demo-node-userdata: local.demo-node-userdata: 
 Resource 'data.aws_region.current' not found for variable 
'data.aws_region.current.name'       

Is there any reason why it wouldn't be able to access the data source? I'm fairly new to Terraform but I've done some googling and couldn't find a clear answer :/

**Tags:** amazon-web-services, kubernetes, terraform


---

## 1 answers

### Answer by username_1 on 2018-06-14. Score: 2 | Accepted answer

You need to pass that info to your module or also declare it in your module again. For example, for the region, pass it as a variable to the module:
module "foo" {
  ...
  current_region = "${data.aws_region.current.name}"
  ...
}

Or add it inline in your module, just like you did in your main.tf

> **Comments:**
> **username_0**: I ended up adding it inline to the module and that worked, I've accepted as the answer. Thanks for your help.  

---

