TF-004 Interact with Terraform modules Practice Question
Which TWO statements are correct when refactoring a monolithic Terraform configuration into modules?
⚠ Common exam trap
A common misconception is that modules must be physically separated from the root module or that they must contain only one resource, when in fact modules are about logical grouping and can be nested locally.
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
✓
Module outputs are necessary to expose values to the root module.
Module outputs are the mechanism by which a root module accesses values from child modules. Without outputs, any resource attributes created inside a module remain encapsulated and inaccessible to the calling configuration, making it impossible to use those values for interpolation or to pass them to other resources or modules.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
All modules must reside in a separate directory outside the root module.
Why it's wrong here
Terraform modules can be sourced from local paths within the same project directory structure, not exclusively from external locations. While remote sources like the Terraform Registry, Git repositories, or S3 buckets are common for shared modules, local modules are frequently used for organizing components within a single configuration. This flexibility allows for better project structure and development workflows without requiring all modules to be physically separate from the root module's directory.
- ✗
A module should contain only one resource to keep it simple.
Why it's wrong here
A core purpose of Terraform modules is to encapsulate a collection of related resources that together form a logical, reusable component, such as a VPC, a database instance, or an application tier. Limiting a module to a single resource would negate much of its organizational and reusability benefits, leading to an excessive number of trivial modules and increased complexity in the root configuration. Simplicity in modules comes from clear interfaces and well-defined responsibilities, not from a minimal resource count.
- ✓
Module outputs are necessary to expose values to the root module.
Why this is correct
Module outputs serve as the explicit interface for a child module to return specific values, such as resource IDs, IP addresses, or connection strings, back to its calling module or the root configuration. Without defining these outputs, any values computed or created within the module remain encapsulated and inaccessible to parent modules, preventing them from being used as inputs for other resources or modules in the overall infrastructure. This mechanism ensures controlled data flow and clear dependencies between different infrastructure components.
- ✗
Variables are optional in modules if hardcoded values are acceptable.
Why it's wrong here
While Terraform technically allows hardcoded values within a module, doing so severely diminishes the module's reusability and flexibility, which are primary benefits of modularization. Variables provide the essential mechanism for making modules configurable and adaptable to different environments or use cases without modifying the module's source code. Relying on hardcoded values essentially creates a non-reusable, static component, undermining the principles of infrastructure as code and increasing maintenance overhead.
- ✓
Modules help to organize and reuse infrastructure code.
Why this is correct
Terraform modules are fundamental for structuring complex infrastructure configurations by grouping related resources into logical, manageable units. This encapsulation significantly improves code organization, making large configurations easier to understand, navigate, and maintain. Furthermore, modules enable the reuse of proven infrastructure patterns across different projects or environments, reducing duplication, ensuring consistency, and accelerating deployment times for new infrastructure.
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
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.