Question 416 of 519
Interact with Terraform moduleshardMultiple ChoiceObjective-mapped

Quick Answer

The answer is to define a map variable with environment names as keys and CIDRs as values, then pass the entire map to the module. This is correct because Terraform’s for_each argument iterates over a map or set, and when you use a map variable, each key becomes a unique module instance while the corresponding value provides that instance’s specific CIDR block. On the HashiCorp Terraform Associate TF-003 exam, this tests your understanding of how for_each differs from count—count with element() on a list works but is less explicit and can break if list order changes, whereas a map gives you stable, self-documenting associations. A common trap is thinking you need to pass individual variables per instance, but the whole point of for_each is to consume a collection. Memory tip: think of a map as a “key-to-value dictionary” where each key is your environment name and the value is its unique CIDR—this keeps your module calls clean and scalable.

TF-003 Interact with Terraform modules Practice Question

This TF-003 practice question tests your understanding of interact with terraform modules. Match the stated requirement to the specific cloud service, access model, or configuration option — many options are valid in isolation but not for this scenario. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

An organization uses Terraform modules to provision multiple environments. They have a module 'vpc' that uses a for_each argument in the root module to create VPCs per environment. Each VPC requires a unique CIDR block passed via variable. What is the best practice to pass different CIDRs per instance?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "best"

    Why it matters: Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

Question 1hardmultiple choice
Review the full subnetting walkthrough →

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

Define a map variable with environment names as keys and CIDRs as values, then pass the entire map to the module.

Option D is correct because using a map variable with for_each allows each instance to receive its own CIDR. Option A is wrong because count combined with element() on a list works but is less clear than a map. Option B is wrong because a map already provides key-value association. Option C is wrong because hardcoding is not scalable.

Key principle: Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.

Answer analysis

Option-by-option breakdown

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

  • Define a map variable with environment names as keys and CIDRs as values, then pass the entire map to the module.

    Why this is correct

    Using a map variable allows clear association between each module instance and its CIDR; it integrates naturally with for_each.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    CIDR notation defines the prefix length.

  • Hardcode the CIDR within each module block.

    Why it's wrong here

    Hardcoding reduces reusability and makes changes error-prone; it's not a best practice.

  • Use a list variable for CIDRs and reference them with count.index and element().

    Why it's wrong here

    While possible, using a map is more explicit and easier to maintain when keys are environment names, especially if not all environments are in the list.

  • Use a module output to fetch the CIDR from a data source.

    Why it's wrong here

    Data sources are for reading existing resources, not for parameterizing module inputs per instance.

Common exam traps

Common exam trap: usable hosts are not the same as total addresses

Subnetting questions often tempt you into counting all addresses. In normal IPv4 subnets, the network and broadcast addresses are not usable host addresses.

Detailed technical explanation

How to think about this question

Subnetting questions test whether you can identify the network, broadcast address, usable range, mask and correct subnet. Slow down enough to calculate the block size correctly.

KKey Concepts to Remember

  • CIDR notation defines the prefix length.
  • Block size helps identify subnet boundaries.
  • Network and broadcast addresses are not usable hosts in normal IPv4 subnets.
  • The required host count determines the smallest suitable subnet.

TExam Day Tips

  • Write the block size before choosing the subnet.
  • Check whether the question asks for hosts, subnets or a specific address range.
  • Do not confuse /24, /25, /26 and /27 host counts.

Key takeaway

Count usable hosts — not total addresses — and remember that the network and broadcast addresses are not available to hosts in standard IPv4 subnets.

Real-world example

How this comes up in practice

A network engineer segments a warehouse floor into three subnets: 20 scanners, 5 printers, and 2 management hosts. Picking the wrong mask wastes addresses or leaves too few usable hosts. Exam questions test whether you can apply CIDR notation, calculate block size, and identify the correct usable-host range for a given prefix.

What to study next

Got this wrong? Here's your next step.

Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related TF-003 subnetting questions on CIDR, address ranges, and subnet selection.

Related practice questions

Related TF-003 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free TF-003 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this TF-003 question test?

Interact with Terraform modules — This question tests Interact with Terraform modules — CIDR notation defines the prefix length..

What is the correct answer to this question?

The correct answer is: Define a map variable with environment names as keys and CIDRs as values, then pass the entire map to the module. — Option D is correct because using a map variable with for_each allows each instance to receive its own CIDR. Option A is wrong because count combined with element() on a list works but is less clear than a map. Option B is wrong because a map already provides key-value association. Option C is wrong because hardcoding is not scalable.

What should I do if I get this TF-003 question wrong?

Review block sizes, usable host formulas (2^n − 2), and how to find network and broadcast addresses for /24 through /30. Then practise related TF-003 subnetting questions on CIDR, address ranges, and subnet selection.

Are there clue words in this question I should notice?

Yes — watch for: "best". Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

What is the key concept behind this question?

CIDR notation defines the prefix length.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 24, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This TF-003 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-003 exam.