TF-004 Understand Terraform's purpose Practice Question
A company has a Terraform configuration that works correctly in us-east-1 but fails in us-west-2 due to resource availability. What is the best way to handle this?
⚠ Common exam trap
A common trap on the HashiCorp Terraform exam is thinking that `count` or `for_each` can directly handle regional resource differences. In reality, those meta-arguments require a data source to dynamically determine the available resources in each region, making the data source the correct approach.
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 data sources
Data sources allow Terraform to query the target region for available resources at plan time, enabling dynamic configuration that adapts to regional differences. By using a data source to filter or validate resource availability, the configuration can fail gracefully or select an alternative resource without hardcoding region-specific values.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Hardcode region in resources
Why it's wrong here
Hardcoding a region directly into resource blocks, such as `region = "us-east-1"`, severely limits the configuration's portability and reusability. This approach necessitates manual modification of the configuration every time it needs to be deployed to a different region or if regional specifics change, making it inflexible and prone to errors. It fails to dynamically adapt to varying regional requirements or availabilities, forcing a static, non-parameterized deployment model.
- ✗
Use count
Why it's wrong here
The `count` meta-argument is designed to create multiple identical instances of a single resource block, iterating to produce N copies of the exact same resource definition. While useful for scaling out identical components, it does not provide a mechanism to conditionally select or configure resources based on unique regional attributes or availability. `count` simply replicates the defined resource, lacking the logic to adapt to distinct regional differences or fetch region-specific information dynamically.
- ✓
Use data sources
Why this is correct
Data sources are a powerful Terraform feature that allows configurations to query and retrieve information from external systems, such as cloud provider APIs, during the plan phase. This enables dynamic fetching of region-specific attributes like available AMI IDs, instance types, or subnet configurations, which can then be used to configure resources adaptively. By leveraging data sources, the configuration can dynamically adjust to regional differences and ensure resource compatibility without hardcoding.
- ✗
Use provisioners
Why it's wrong here
Provisioners are lifecycle hooks that execute scripts or commands on a local machine or a remote resource *after* that resource has been created or *before* it is destroyed. Their purpose is post-creation configuration or pre-destruction cleanup, not to influence the selection or creation of other Terraform resources based on dynamic conditions like regional availability. Provisioners operate on an *existing* resource instance and cannot determine which resources should be created or how they should be configured based on external, regional data.
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.