Bitzu

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

Single choice

A module block is labeled "db" and the child declares output "endpoint". How do you reference it?

  1. output.db.endpoint
  2. var.db.endpoint
  3. module.db.endpoint
  4. db.module.endpoint
Show answer

Answer: C. module.db.endpoint

The pattern is module.LABEL.OUTPUT_NAME. The other forms are not valid addresses.

Select all that apply

Which of these are valid meta-arguments in a module block?

  1. for_each
  2. provider
  3. providers
  4. depends_on
  5. 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

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module