Courseiva
Interact with Terraform moduleshardMultiple ChoiceObjective-mapped

TF-004 Interact with Terraform modules Practice Question

A module requires a specific provider configuration with aliases. The root module has two provider configurations: provider 'aws' (default) and provider 'aws' with alias = 'uswest'. The module uses the us-west alias. How should the module block be configured to ensure the correct provider is used?

⚠ Common exam trap

A common misconception is that required_providers inside a module can select an alias, when in fact it only declares provider requirements and version constraints.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Use the providers argument in the module block: providers = { aws = aws.uswest }.

Terraform uses the `providers` argument in a module block to explicitly map provider configurations from the root module into the module. Since the root module has two AWS provider configurations (default and `uswest` alias), and the module requires the us-west alias, the mapping `providers = { aws = aws.uswest }` ensures the module uses the aliased provider. Without this explicit mapping, Terraform would default to the root module's default provider, which may not have the correct region or settings.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Set required_providers inside the module to include the alias.

    Why it's wrong here

    Setting `required_providers` inside a module defines the module's provider dependencies, specifying attributes like source and version constraints. However, it does not establish a mapping between the module's internal provider name and a specific, potentially aliased, provider configuration from the calling root module. `required_providers` declares *what* providers the module needs, not *how* those needs are fulfilled by specific configurations passed down.

  • Use the providers argument in the module block: providers = { aws = aws.uswest }.

    Why this is correct

    The `providers` argument within a `module` block is the correct and explicit mechanism for passing specific provider configurations from the calling module to a child module. By using `providers = { aws = aws.uswest }`, the child module's expectation for an `aws` provider is satisfied by the `uswest` aliased `aws` provider configuration defined in the root module. This ensures the module operates with the intended, aliased provider configuration.

  • Include a provider block inside the module block with alias = 'uswest'.

    Why it's wrong here

    Including a `provider` block directly inside a `module` block is syntactically invalid in Terraform. Provider configurations, defined by `provider` blocks, are top-level constructs within a Terraform configuration file or nested within a `terraform` block for specific settings. Attempting to nest a `provider` block within a `module` call will result in a parsing error, as it violates Terraform's configuration language structure.

  • Do nothing; Terraform automatically uses the default provider.

    Why it's wrong here

    Doing nothing means the module will attempt to use the default, unaliased provider configuration (e.g., `aws`) available in the calling module. If the module's resources are explicitly configured to use an aliased provider (e.g., `provider = aws.uswest`), this will lead to errors because the required aliased configuration was not provided. Terraform does not automatically infer or map a specific aliased provider when one is explicitly expected by the module.

About these practice questions

One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.