TF-004 Use Terraform outside the core workflow Practice Question
An organization wants to use Terraform to manage infrastructure in multiple environments (dev, staging, prod) with the same configuration but different variable values. Which approach should they use?
⚠ Common exam trap
HashiCorp often tests the misconception that workspaces are the only way to manage multiple environments, but the trap here is that candidates may overlook the need for separate variable files alongside workspaces, or incorrectly think that a single state file with environment variables is sufficient for isolation.
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 Terraform workspaces and separate variable files
Terraform workspaces allow you to manage multiple distinct sets of infrastructure resources within the same configuration by maintaining separate state files. By combining workspaces with separate variable definition files (e.g., `dev.tfvars`, `prod.tfvars`), you can reuse the same configuration code while applying environment-specific variable values, avoiding duplication and ensuring consistency across environments.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create separate directories with duplicated configurations
Why it's wrong here
Creating separate directories for each environment, each containing a full copy of the Terraform configuration, inevitably leads to significant code duplication. This approach makes maintaining consistency across environments extremely challenging, as any change or bug fix must be manually replicated in every directory. Such duplication increases the likelihood of configuration drift and errors, making infrastructure management inefficient and prone to mistakes.
- ✓
Use Terraform workspaces and separate variable files
Why this is correct
Terraform workspaces allow for managing multiple distinct states for a single configuration, effectively isolating environments like `dev`, `staging`, and `prod` within the same codebase. By combining workspaces with separate `*.tfvars` files for each environment, organizations can reuse the core infrastructure definition while providing environment-specific values for variables. This method ensures state isolation and parameter differentiation without duplicating the underlying configuration, promoting consistency and maintainability.
- ✗
Use a single state file with environment variables
Why it's wrong here
Utilizing a single Terraform state file across multiple environments, even when differentiating configurations with environment variables, presents a critical risk of cross-environment interference and data corruption. The state file tracks the real-world resources managed by Terraform; a single file would attempt to manage all environments simultaneously, leading to resource conflicts, accidental modifications, or deletions across environments. This approach fundamentally undermines the principle of infrastructure isolation, making it highly unsuitable for managing distinct environments.
- ✗
Use different versions of Terraform for each environment
Why it's wrong here
Employing different versions of Terraform for each environment introduces unnecessary complexity and significant operational overhead without providing any tangible benefit for environment isolation. This practice can lead to compatibility issues with providers and modules, inconsistent behavior, and makes troubleshooting considerably more difficult. Maintaining multiple Terraform versions across environments complicates CI/CD pipelines and increases the risk of unexpected changes in resource provisioning due to version-specific behaviors, making it an impractical and ill-advised strategy.
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.