Terraform Associate 004 ยท Terraform modules
How do you call and use a module?
module block, passing inputs, referencing module.NAME.OUTPUT, count/for_each on modules, providers passed to modules (5c).
Key points
- Declare module "label" { source = ... } and pass inputs as arguments.
- Read results with module.LABEL.OUTPUT.
- The block accepts the meta-arguments count or for_each (not both), providers, and depends_on.
- Run terraform init after adding the block or changing its source.
Source: https://developer.hashicorp.com/terraform/language/block/module
Practice questions
A module block is labeled "db" and the child declares output "endpoint". How do you reference it?
- output.db.endpoint
- var.db.endpoint
- module.db.endpoint
- db.module.endpoint
Show answer
Answer: C. module.db.endpoint
The pattern is module.LABEL.OUTPUT_NAME. The other forms are not valid addresses.
Which of these are valid meta-arguments in a module block?
- for_each
- provider
- providers
- depends_on
- alias_all
Show answer
Answer: A. for_each, C. providers, D. depends_on
for_each, providers and depends_on are module meta-arguments. provider (singular) belongs to resources, and alias_all does not exist.
True or false: one module block may set both count and for_each to create instances.
Show answer
Answer: False
False. The two meta-arguments are mutually exclusive.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
