Courseiva
Understand Terraform basicseasyMultiple ChoiceObjective-mapped

TF-004 Understand Terraform basics Practice Question

A team is using Terraform to manage infrastructure across multiple environments (dev, staging, prod). They want to reuse the same root module configuration but with different variable values. Which approach is the most efficient?

⚠ Common exam trap

HashiCorp often tests the misconception that environment variables alone can replace state isolation, but the trap here is that environment variables only affect input values, not state management, so they cannot prevent cross-environment state conflicts.

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

Terraform workspaces allow you to manage multiple distinct sets of infrastructure resources (e.g., dev, staging, prod) from the same root module configuration by maintaining separate state files for each workspace. This avoids duplicating code or manually managing state file switching, making it the most efficient approach for reusing configuration with different variable values 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.

  • Use environment variables to switch between configurations

    Why it's wrong here

    Environment variables are primarily used to pass dynamic values into a Terraform configuration, such as AWS region or access keys, at runtime. However, they cannot directly control or switch between different Terraform state files or backend configurations, which is essential for isolating infrastructure environments. Managing separate environments requires distinct state management, which environment variables alone cannot achieve, making them unsuitable for this purpose.

  • Use a single state file that includes all environments

    Why it's wrong here

    Using a single state file for all environments, such as development, staging, and production, is highly discouraged due to significant risks. This approach creates a single point of failure, where an `apply` operation intended for one environment could inadvertently modify or destroy resources in another. Furthermore, it complicates access control, makes concurrent operations difficult, and increases the blast radius of any configuration error, leading to potential widespread outages.

  • Copy the entire configuration into separate directories for each environment

    Why it's wrong here

    Copying the entire Terraform configuration into separate directories for each environment, while providing state isolation, leads to significant code duplication. This practice makes maintaining consistency across environments extremely challenging, as any change or bug fix must be manually replicated in multiple locations. Such duplication inevitably results in configuration drift, increased operational overhead, and makes updates cumbersome and error-prone over time.

  • Use Terraform workspaces

    Why this is correct

    Terraform workspaces provide an elegant solution for managing multiple distinct environments using a single, shared configuration. Each workspace maintains its own isolated state file within the configured backend, ensuring that operations in one environment do not affect others. This approach promotes code reusability, reduces duplication, and simplifies the management of infrastructure across development, staging, and production environments effectively.

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.