tfvars & modules

835 views
Skip to first unread message

Tennis Smith

unread,
Jun 22, 2016, 12:39:32 PM6/22/16
to Terraform
Hi,

I'm not able to pass a variable from an included tfvars file to a module.  Here is my setup. 

"terraform/modules/aws/main.tf"

variable "aws_account_id" {}

provider "aws" {
allowed_account_ids = ["${var.aws_account_id}"]
}


"terraform/main.tf"

module "aws" {
source = "./modules/aws"
}


"terraform/vars.tfvars" contains

aws_account_id = "969696969696"



But I get the following error:

 terraform plan -var-file=vars.tfvars   
  Error configuring: 1 error(s) occurred:
* module.aws: missing dependency: var.aws_account_id

What am I missing? Do I have to explicitly pass the variable somehow in the "module" definition?

Tks,
-T


David Adams

unread,
Jun 22, 2016, 11:04:53 PM6/22/16
to terrafo...@googlegroups.com
Yep, you've already guessed the answer. Your variable is only scoped to the tf files in the current directory. To pass it to the aws module you can do:

    module "aws" {
      source = "./modules/aws"
      aws_account_id = "${var.aws_account_id}"
    }

It feels a little silly when passing directly through in that way to a local module but modules are designed to be completely isolated units that can be pulled from git, remote files, local files, etc. so this is really the only design that would work without inducing some weird surprises.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/3b535725-9ec6-41f2-8dda-673fb2ee4e25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tennis Smith

unread,
Jun 23, 2016, 7:01:32 AM6/23/16
to Terraform
That worked.

Thanks for the reply, David.

-Tennis 
Reply all
Reply to author
Forward
0 new messages