TF-004 Read, generate and modify configuration Practice Question
Which TWO statements about Terraform data sources are correct?
⚠ Common exam trap
A common mix-up: candidates confuse data sources with managed resources, assuming they require an apply to be available or that they create infrastructure, when in fact they are read-only and resolved during planning.
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
✓
Data sources can be used in count and for_each.
Terraform data sources are regular resources that support the `count` and `for_each` meta-arguments, allowing you to dynamically fetch data for multiple instances or conditional logic. This enables patterns like iterating over a list of external IDs to retrieve corresponding data from a provider, such as fetching multiple AMI IDs for different regions.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Data sources can be used in count and for_each.
Why this is correct
Data sources are evaluated during the plan phase, making their output available to Terraform's meta-arguments. This allows their attributes, such as a list of IDs or names fetched from an external system, to dynamically drive the `count` or `for_each` argument of a resource or module. Consequently, you can provision multiple instances of infrastructure based on existing external data, enabling highly dynamic and data-driven configurations. This is a powerful pattern for managing infrastructure that adapts to external state.
- ✓
Data sources can fetch information from external systems.
Why this is correct
The fundamental purpose of Terraform data sources is to retrieve information from various external systems, such as cloud provider APIs, on-premise infrastructure, or even local files. They act as read-only interfaces to existing infrastructure or external data, allowing Terraform to incorporate this information into its configuration. This enables referencing external state without managing it directly, facilitating integration with pre-existing environments or services.
- ✗
Data sources are only available after applying the configuration.
Why it's wrong here
This statement is incorrect because Terraform data sources are evaluated and their data is fetched during the `terraform plan` phase, not after `apply`. The information retrieved by data sources is crucial for Terraform to construct a complete execution plan, determining what changes need to be made. If they were only available after applying, they couldn't inform the plan or be used in resource arguments that are resolved during planning.
- ✗
Data sources are used to create new infrastructure.
Why it's wrong here
This statement is incorrect because data sources are explicitly designed for reading existing infrastructure or external data, not for creating new resources. Their role is to fetch attributes of pre-existing components, making that information available within the Terraform configuration. Creating or modifying infrastructure is the exclusive function of `resource` blocks, which manage the lifecycle of infrastructure objects.
- ✗
Data sources cannot be used inside modules.
Why it's wrong here
This statement is incorrect; data sources are frequently and effectively used inside Terraform modules. Modules serve as reusable containers for infrastructure configurations, and including data sources within them allows the module to dynamically fetch necessary external information. This enables modules to be more flexible and self-contained, as they can retrieve specific details pertinent to their operation without requiring them to be passed in as explicit input variables.
Go deeper
Related to this question
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 →
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.