patternkubernetesMinor
Terraform Issue - Can't find Data Source in Sub Module?
Viewed 0 times
cansourceissuemodulesubfinddataterraform
Problem
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:
In 'main.tf' I've got the following
When I run a 'terraform plan' I get the following error which comes from eks-worker-nodes.tf :
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 :/
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.tfIn '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 :/
Solution
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:
Or add it inline in your module, just like you did in your
module "foo" {
...
current_region = "${data.aws_region.current.name}"
...
}Or add it inline in your module, just like you did in your
main.tfCode Snippets
module "foo" {
...
current_region = "${data.aws_region.current.name}"
...
}Context
StackExchange DevOps Q#4299, answer score: 2
Revisions (0)
No revisions yet.