Courseiva
Implement and maintain statemediumDrag & DropObjective-mapped

TF-004 Implement and maintain state Practice Question

Drag and drop the steps to use Terraform modules from the registry 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

Write the module block in main.tf, then run terraform init, then set input variables in terraform.tfvars, then run terraform plan and terraform apply.

Registry modules are sourced; init downloads, variables configure, plan/apply deploy.

Answer analysis

Option-by-option breakdown

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

  • Write the module block in main.tf, then run terraform init, then set input variables in terraform.tfvars, then run terraform plan and terraform apply.

    Why this is correct

    This sequence correctly follows the standard Terraform workflow for incorporating and deploying modules. First, the module block, including its `source` attribute, must be defined in the configuration files (e.g., `main.tf`) to declare the module dependency. `terraform init` then reads this configuration to download the specified module source and initialize backend and provider plugins. After initialization, input variables for the module can be set in `terraform.tfvars` or other methods. Finally, `terraform plan` and `terraform apply` can execute, using the downloaded module and provided variables to manage infrastructure.

  • Run terraform init, then write the module block, then set input variables, then run terraform plan and apply.

    Why it's wrong here

    This order is incorrect because `terraform init` is responsible for discovering and downloading modules referenced in the configuration. If `terraform init` is executed *before* the module block is written, Terraform will find no module sources to download or initialize, leading to an incomplete setup. The subsequent `terraform plan` or `apply` commands would then fail, as the required module code would be missing from the `.terraform` directory, preventing any infrastructure provisioning.

  • Write the module block, then set input variables, then run terraform init, then run terraform plan and apply.

    Why it's wrong here

    While technically possible to define variables before `terraform init`, this sequence is suboptimal and deviates from the standard Terraform workflow. `terraform init` is crucial for downloading the module's source code and initializing necessary providers and backend configurations. If `init` is run *after* variables are set but *before* `plan`/`apply`, the `plan` and `apply` commands would still fail if the module wasn't downloaded, or if providers weren't initialized. The correct practice is to initialize the working directory first to ensure all dependencies are present and validated before attempting to evaluate the configuration with variables.

  • Write the module block, then run terraform plan and apply, then run terraform init, then set input variables.

    Why it's wrong here

    This sequence is fundamentally flawed because `terraform plan` and `terraform apply` both require a fully initialized working directory, which includes having all referenced modules downloaded. Attempting to run `terraform plan` or `apply` immediately after writing the module block but *before* `terraform init` will result in an error. Terraform will report that the module source cannot be found, as `init` has not yet fetched the module's code from its specified `source`. The module's code must be present locally for Terraform to parse and evaluate its resources.

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.