Question 60 of 428
TF-004 Interact with Terraform modules Practice Question
A module block references a module with version constraint '>= 2.0, < 3.0'. An older version 1.5 is already cached from a previous init. The team wants to ensure they use a newer version. After running terraform init -upgrade, what happens?
⚠ Common exam trap
HashiCorp often tests the misconception that `terraform init -upgrade` will always install the absolute latest version (like 3.0) regardless of constraints, or that a cached version will be used if it is present, when in fact the flag forces a fresh resolution within the defined range.
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
✓
Terraform upgrades to the latest version in the range 2.x that is not yet cached.
`terraform init -upgrade` instructs Terraform to ignore any cached versions and re-check the registry for the newest available version that satisfies the version constraint `>= 2.0, < 3.0`. Since the constraint excludes 3.0, the latest version in the 2.x series will be selected and downloaded, overwriting the cached 1.5 version.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Terraform upgrades to version 3.0 because it is the latest.
Why it's wrong here
The `terraform get -upgrade` command strictly adheres to the version constraints specified in the module block. If the constraint is, for example, `~> 2.0` (meaning `>= 2.0.0, < 3.0.0`), Terraform will not consider any version 3.0.0 or higher, even if it represents the absolute latest release available from the module source. The `-upgrade` flag only instructs Terraform to find the newest version *within* the allowed range.
- ✗
Terraform returns an error because version 1.5 is incompatible with the constraint.
Why it's wrong here
Terraform enforces module version constraints only during the resolution and download phase, not merely upon detecting a cached version. While version 1.5 is indeed incompatible with a constraint like `~> 2.0`, its presence in the local cache does not automatically trigger an error. An error would only occur if Terraform attempted to resolve the module and *could not find any* version satisfying the constraint, which is not the scenario described.
- ✗
Terraform uses the cached version 1.5 because it is already present.
Why it's wrong here
The `-upgrade` flag explicitly overrides Terraform's default behavior of using locally cached module versions. When this flag is provided with `terraform get`, Terraform is instructed to ignore any existing cached versions, including 1.5, and instead query the module source to identify and download the latest available version that fully satisfies the defined version constraint.
- ✓
Terraform upgrades to the latest version in the range 2.x that is not yet cached.
Why this is correct
When `terraform get -upgrade` is executed, Terraform first evaluates the module's version constraint, such as `~> 2.0` (meaning `>= 2.0.0, < 3.0.0`). It then queries the module source to identify the absolute newest version available that falls within this specified range. Finally, it downloads this newly identified, latest compatible version, effectively upgrading the module if a newer one exists within the constraint and is not yet cached.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jul 4, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.