TF-004 Understand IaC concepts Practice Question
A company is managing multiple cloud environments (dev, test, prod) using Terraform. They want to ensure consistent configurations across environments while allowing environment-specific values. Which IaC practice best supports this?
⚠ Common exam trap
Candidates often think data sources can replace variables for environment separation, but data sources only read existing infrastructure and cannot define or override configuration values. Workspaces and variables are required to manage environment-specific settings without duplicating code.
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
✓
Using variables and workspaces
Using variables and workspaces allows you to define a single set of Terraform configurations while dynamically injecting environment-specific values via variable definitions (e.g., terraform.tfvars or -var-file) and isolating state per environment using workspaces (terraform workspace). This avoids duplication and ensures consistent resource definitions across dev, test, and prod, with only the variable values differing.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Using data sources only
Why it's wrong here
Using data sources only is insufficient because data sources are designed to query and retrieve information about existing infrastructure or external data, not to define or manage the creation of new resources with environment-specific configurations. While they can fetch environment-specific IDs or attributes, they do not provide a mechanism to parameterize resource definitions, such as varying instance types or network CIDRs, across distinct development and testing environments from a single configuration. This approach would still require hardcoding or duplicating resource definitions to achieve environment differentiation.
- ✗
Hardcoding values
Why it's wrong here
Hardcoding values directly within the Terraform configuration files for each environment makes the infrastructure code rigid and highly inflexible. This practice necessitates manual modification of the core .tf files whenever an environment-specific attribute (like an instance size or database name) needs to change, or when deploying to a new environment. Such direct embedding of values significantly increases the risk of introducing errors, makes the configuration difficult to maintain, and prevents the reuse of the same codebase across different stages of the development lifecycle.
- ✗
Duplicating configuration files
Why it's wrong here
Duplicating configuration files for each environment (e.g., dev.tf, test.tf) creates significant maintenance overhead and introduces a high risk of inconsistencies. When a common resource definition or module needs an update, the change must be manually applied to every duplicated file, which is prone to human error and can lead to configuration drift between environments. This approach undermines the principle of "Don't Repeat Yourself" (DRY) and makes managing infrastructure at scale cumbersome and unreliable.
- ✓
Using variables and workspaces
Why this is correct
Using variables allows the Terraform configuration to be parameterized, enabling different values (e.g., resource sizes, region names, environment tags) to be supplied dynamically for distinct environments without altering the core .tf files. Concurrently, Terraform workspaces provide isolated state files for each environment (e.g., dev, test), allowing a single, consistent configuration to manage multiple independent deployments. This powerful combination ensures flexibility, prevents state file conflicts, and maintains consistency across all environments from a unified codebase.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.