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
Your
foo-module/terraform.tfvars
doesn't define a variable namedfoo_nets
, it only defines a default value for a variable namedfoo_nets
if that variable happens to exist. You still have to define the variable somewhere in the terraform files in thefoo-module
folder like this: