Open ryan-roemer opened 5 years ago
I’ve been trying to wrangle a seemingly simple idea: I want to conditionally include a sub-module
based on a variable.
Things I’ve tried that failed:
count
: Idea - set count to 0
if not using.
module "foo" {
count = "${var.use_foo ? 1 : 0}"
source = "./modules/foo"
}
source
: Idea - swap real submodule for a completely empty one.
module "foo" {
source = "${var.use_foo ? "./modules/foo" : "./modules/empty"}"
}
These things seem related to this:
module.count
is now a reserved word. When implemented in the future, will presumably get us there. See https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/#module-count-and-for_each
For a long time, users have wished to be able to use the
count
meta-argument within module blocks, allowing multiple instances of the same module to be created more easily.Again, we have been laying the groundwork for this during Terraform 0.12 development and expect to complete this work in a later release. Along with
count
, module blocks will also accept the new for_each argument described for resources above, with similar results.This feature is particularly complicated to implement within Terraform's existing architecture, so some more work will certainly be required before we can support this. To avoid further breaking changes in later releases, 0.12 will reserve the module input variable names
count
and for_each in preparation for the completion of this feature.
Idea: