Courseiva
Use the core Terraform workfloweasyMultiple ChoiceObjective-mapped

TF-004 Use the core Terraform workflow Practice Question

A team uses Terraform to manage infrastructure. They have multiple configuration directories for different environments (dev, staging, prod). They want to reuse common modules across environments. Which approach aligns with the core Terraform workflow best practices?

⚠ Common exam trap

HashiCorp often tests the misconception that workspaces are the primary mechanism for managing multiple environments, but the trap here is that workspaces with a local backend lack the isolation and locking required for team-based workflows, making variable files with separate remote state backends the recommended practice.

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 a single configuration with separate state files and variable files for each environment

It follows the core Terraform workflow of separating configuration from state and using variable files to manage environment-specific differences. By maintaining a single configuration directory with separate state files (e.g., via different backends or state file paths) and variable files (e.g., `dev.tfvars`, `prod.tfvars`), the team avoids duplication and ensures that all environments use the same module versions and resource definitions, which is a best practice for consistency and maintainability.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use a single configuration with separate state files and variable files for each environment

    Why this is correct

    This approach leverages a single, consistent Terraform configuration module, promoting code reuse and reducing potential for configuration drift across environments. Environment-specific differences are managed through distinct `terraform.tfstate` files, typically stored in a remote backend, and separate variable definition files (`.tfvars`), which are passed during `terraform apply` using the `-var-file` flag. This ensures strong isolation between environments while maintaining a unified codebase, crucial for consistent deployments.

  • Use workspaces with state stored in a local backend

    Why it's wrong here

    Using workspaces with a local backend is highly problematic for team collaboration due to the critical absence of state locking mechanisms. Without state locking, concurrent `terraform apply` operations from different team members can lead to race conditions, resulting in corrupted state files and inconsistent infrastructure deployments. Furthermore, managing and sharing local state files across a team is cumbersome and error-prone, making this unsuitable for production environments.

  • Copy the configuration into each environment directory and modify as needed

    Why it's wrong here

    Copying the entire Terraform configuration into separate directories for each environment introduces significant maintenance overhead and guarantees configuration drift over time. Any bug fixes or feature updates to the infrastructure definition must be manually replicated across all copies, leading to inconsistencies and increased potential for human error. This method negates the benefits of infrastructure as code by creating disparate, unmanaged versions of the same infrastructure.

  • Create separate Terraform configurations for each environment with hardcoded values

    Why it's wrong here

    Creating entirely separate Terraform configurations for each environment, especially with hardcoded values, leads to extensive code duplication and makes global changes incredibly difficult and error-prone. This approach lacks parameterization, meaning any common resource definitions or provider configurations must be repeated in every environment's configuration. Such redundancy increases the likelihood of inconsistencies and significantly complicates maintenance, as updates require modifying multiple, distinct codebases.

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 →

How Courseiva writes practice questions · Editorial policy

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.