TF-Associate-004 - Terraform modules (11% of the exam) - Section 5c

Use modules in configuration.

A module block calls a module, passes inputs, and its outputs are referenced as module.name.output. Candidates should know count and for_each apply to module blocks, and how a called module's resources are addressed in state.

module blockpassing input valuesmodule output referencecount and for_each on modules

Practice question for this objective

Free sampleTerraform moduleseasy

A practitioner defines a child module named 'network' and wants the root configuration to reference the ID of a VPC that the module creates. The module already declares an output called 'vpc_id'. Which expression should the root configuration use to read that value?

module "network" {
  source = "./modules/network"
  cidr   = "10.0.0.0/16"
}
  • Amodule.network.outputs.vpc_id
  • Bvar.network.vpc_id
  • Cnetwork.vpc_id
  • Dmodule.network.vpc_id Correct
Reference a child module's exported output from the calling configuration using the module.NAME.OUTPUT syntax. Outputs declared inside a child module are exposed to the caller under the address module.<module name>.<output name>; there is no intermediate 'outputs' component and the module keyword is required to distinguish it from resource references.

Why A is wrong: This looks plausible because outputs are what is being read, but Terraform does not insert an 'outputs' segment into the reference address, so it fails to resolve.

Why B is wrong: The var prefix reads input variables of the current module, not values exported by a child module, so it cannot reach the module's output.

Why C is wrong: Omitting the module keyword makes this look like a resource reference, but a bare name without the module prefix does not address a called module's output.

Why D is correct: A child module's exported output is read with the syntax module.<NAME>.<OUTPUT>, so module.network.vpc_id returns the value the module exposed.

See more TF-Associate-004 practice questions, answers explained.

Exam traps in Terraform modules

Answers that look right on this material and are not. Each one is a distractor from a different question in the TF-Associate-004 bank for this domain.

  • var.network.subnet_id, reading the child module's variable through the var namespace.

    Why it is wrong: This is tempting because var addresses variables, but var refers only to the current module's own variables and cannot reach into another module's scope.

  • By exporting the value as an output in the root module, which the child module then reads automatically.

    Why it is wrong: Outputs expose values from a module to its caller, not the other way round, so a root output cannot feed a value down into a child.

  • To expose a computed result from the module so that the calling configuration can consume it elsewhere.

    Why it is wrong: This describes an output block rather than an input variable; outputs send values upward to the caller, whereas inputs receive values from the caller.

More in this domain

Back to all Terraform modules objectives, or the TF-Associate-004 cert hub.

Examworthy is not affiliated with or endorsed by HashiCorp. Original, blueprint-aligned practice material only.