How can I pass the tfvars from another module?

233 views Asked by At

So here's my setup: main.tf:

module "foo" {
  source      = "../../../foo-module"
  name          = "bar"
  foo_nets = "${var.foo_nets}"
}

foo-module/terraform.tfvars:

foo_nets = ["1", "2", "3"]
➜  terraform plan -var-file=../../foo-module/terraform.tfvars -target=module.foo 
Error: module 'foo': unknown variable referenced: 'foo_nets'; define it with a 'variable' block
1

There are 1 answers

0
Mark B On BEST ANSWER

Your foo-module/terraform.tfvars doesn't define a variable named foo_nets, it only defines a default value for a variable named foo_nets if that variable happens to exist. You still have to define the variable somewhere in the terraform files in the foo-module folder like this:

variable "foo_nets" {
}