2

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 :/

1

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

  • I ended up adding it inline to the module and that worked, I've accepted as the answer. Thanks for your help. – Caledonia91 Jun 14 '18 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.