Looked for an answer for this question in multiple posts but found solutions for a simpler scenarios only.
Let's say I have a module called a
and this module depends on multiple different modules, let's call them b
and c
.
module "a" {
source = ./a
depends_on = [module.B, module.C]
b_id = module.b.id
c_id = module.c.id
}
module "b" {
source = ./b
}
module "c" {
source = ./c
}
In the naive scenario both modules b
and c
will be created before we create module a
, but what if I want to let the user of module a
to create it's own instances of b
and c
and just pass their ids to a
without us creating b
and c
.
I'm aware of the count
trick on resources detailed here, but it works only for resources and not modules and to make it work here I will need to apply it to every resource inside the modules which will create a cumbersome code.
I also saw terraform conditional creation of objects but this solution works good if the main module/resource has just one conditional attribute, what if we have 10 modules that can be provisioned to us by the user or need to be created inline?