Question 1 · choose 1
A team calls the same app module three times, once each for dev, stage and prod, with three copies of the module block that differ only in a few inputs. How can one module block do this without changing the module itself?
- ASet source to a list of three directories
- BUse for_each on the module block over a map of per-environment settings
- CAdd a dynamic "module" block inside the root module
- DCall the module once and let its variables accept lists of environments
Show the answer and why
ASet source to a list of three directories
Incorrect
source takes a single module location, not a list.
BUse for_each on the module block over a map of per-environment settings
Correct
Module blocks accept for_each (or count), creating one module instance per element.
CAdd a dynamic "module" block inside the root module
Incorrect
dynamic generates nested blocks inside resources, not module calls.
DCall the module once and let its variables accept lists of environments
Incorrect
Possible only by rewriting the module; for_each needs no module changes.
count and for_each work on module blocks just as on resources.
HashiCorp documentation