Courseiva
Use Terraform outside the core workflowmediumDrag & DropObjective-mapped

TF-004 Use Terraform outside the core workflow Practice Question

Drag and drop the steps to use Terraform workspaces for environment separation in the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

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

Create workspace, then Select workspace, then Set environment-specific variables, then Run terraform plan and apply

The correct sequence for using Terraform workspaces is: first create the workspace (if it doesn't exist) to isolate state, then select it to switch to that workspace's state, then set environment-specific variables (e.g., via .tfvars files) to tailor configuration, and finally run terraform plan and apply to manage resources. Workspaces are essential for environment separation, ensuring state isolation and preventing cross-environment interference.

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 workspace, then Select workspace, then Set environment-specific variables, then Run terraform plan and apply

    Why this is correct

    This sequence correctly outlines the process for using Terraform workspaces. You first create a new workspace (e.g., `terraform workspace new dev`) to establish a distinct, isolated state file for a specific environment. Next, you explicitly select that workspace (`terraform workspace select dev`) to ensure all subsequent Terraform operations target its unique state. Only after the correct workspace is active should you define or load environment-specific variables, often through `.tfvars` files or environment variables, to configure resources appropriately for that context. Finally, `terraform plan` and `terraform apply` are executed to provision or modify infrastructure within the selected workspace's scope.

  • Select workspace, then Create workspace, then Set environment-specific variables, then Run terraform plan and apply

    Why it's wrong here

    This sequence is incorrect because `terraform workspace select` requires an existing workspace to switch to. Attempting to select a workspace that has not yet been created will result in an error, as Terraform cannot operate on a non-existent state context. The logical flow dictates that a workspace must first be brought into existence via `terraform workspace new` before it can be chosen for active use, making selection before creation an invalid operation.

  • Set environment-specific variables, then Create workspace, then Select workspace, then Run terraform plan and apply

    Why it's wrong here

    Setting environment-specific variables before creating and selecting a workspace is premature and inefficient. While some variables might be global, many critical environment-specific configurations are intended to be applied within the context of a particular workspace. Defining these variables before the target workspace is active means they might not be correctly associated or could be overridden when the workspace is eventually selected, leading to potential misconfigurations or extra effort.

  • Create workspace, then Set environment-specific variables, then Select workspace, then Run terraform plan and apply

    Why it's wrong here

    This order is incorrect because after creating a new workspace, Terraform does not automatically switch to it; the previously active workspace remains selected. Therefore, setting environment-specific variables immediately after creation but *before* selecting the new workspace means those variables would apply to the *wrong* workspace's context. It is crucial to explicitly `terraform workspace select` the newly created workspace to ensure subsequent variable definitions and operations target the intended isolated state.

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 →

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.