Multiple variable files

664 views
Skip to first unread message

Ron Pantofaro

unread,
Oct 14, 2014, 4:54:32 PM10/14/14
to terrafo...@googlegroups.com
Ok, so I started working with 0.3. Until now I had my variables separated logically between a few files and they also have hierarchy to them.
Now I saw that unless I specify their values in terraform.tfvars (or some other file) it asks me for all the variable values (or keep defaults).
Is there a way to tell terraform to read from multiple var files? perhaps it's solvable with modules?
Let's say I have two sets of variables. Global vars (for example AWS keys) and infrastructure vars (like dns_name of a web server). I want to be able to hold one "global" var file and "use" it (even if it's linking it like i'm doing today) to all my infrastructures (in each one i have the infrastructure specific variables).
Is this possible? (notice that I don't want the root module to pass parameters to child modules, I want the child modules to be able to read from another file completely , or just have terraform be able to read from more than one file).
Hope it was clear.

Ron

Mitchell Hashimoto

unread,
Oct 14, 2014, 5:03:17 PM10/14/14
to Ron Pantofaro, <terraform-tool@googlegroups.com>
Ron,

You can specify `-var-file` to the command-line, but there is no way
to otherwise get multiple var files to work.

Best,
Mitchell
> --
> 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 post to this group, send email to terrafo...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/terraform-tool/8b025b6d-d4ed-436b-ab3f-925b718f7494%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ron Pantofaro

unread,
Oct 14, 2014, 5:04:57 PM10/14/14
to Mitchell Hashimoto, <terraform-tool@googlegroups.com>
would i be able to specify more than one var-file?
and to the module question - is the var files global, or will each module also read a var file in its module folder?

Mitchell Hashimoto

unread,
Oct 14, 2014, 5:06:39 PM10/14/14
to Ron Pantofaro, <terraform-tool@googlegroups.com>
Ron,

Yes, you can specify multiple.

Module parameters must be passed in from the module using it (up to
the root module). For example:

module "consul" {
servers = "${var.servers}"
}

You have to explicitly forward/string along variables through modules.
Without it, modules will not ask for input.

Best,
Mitchell

Ron Pantofaro

unread,
Oct 14, 2014, 5:13:38 PM10/14/14
to Mitchell Hashimoto, <terraform-tool@googlegroups.com>
Is there a way to force terraform to be "silent" if a var isn't in terraform.tfvars but it does have a default?
Reply all
Reply to author
Forward
0 new messages