TF-004 Interact with Terraform modules Practice Question
A team wants to use a networking module from the public Terraform Registry. They need to ensure they always get the latest patch version within the 1.2.x series. Which version constraint should they use in the module block?
⚠ Common exam trap
A common pitfall is confusing `~> 1.2` with `>= 1.2.0, < 2.0.0`. The pessimistic constraint `~> 1.2` restricts updates to patches within the 1.2.x series (`>= 1.2.0, < 1.3.0`), while `>= 1.2.0, < 2.0.0` permits any 1.x version, including minor upgrades. Another subtle trap: `~> 1.2.0` would lock to patches within 1.2.0, but that is not the same as `~> 1.2`.
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
✓
version = "~> 1.2"
Uses the pessimistic version constraint operator `~>`, which in Terraform allows only the rightmost version component to increment. When written as `~> 1.2`, it permits any version `>= 1.2.0` and `< 1.3.0`, effectively locking to the 1.2.x series while allowing patch updates. This matches the requirement to always get the latest patch within 1.2.x without accidentally upgrading to 1.3.0 or 2.0.0.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
version = "= 1.2.0"
Why it's wrong here
This constraint strictly pins the module to the exact version 1.2.0. It prevents any automatic updates, including critical patch releases (e.g., 1.2.1) that often contain important bug fixes or security vulnerability resolutions. While providing absolute stability, this rigidity requires manual intervention for every update, potentially delaying the adoption of necessary improvements and increasing maintenance overhead.
- ✗
version = ">= 1.2.0, < 2.0.0"
Why it's wrong here
This range constraint allows any version starting from 1.2.0 up to, but not including, 2.0.0. It permits both patch updates (e.g., 1.2.1) and minor version updates (e.g., 1.3.0, 1.9.0). While minor versions are generally backward-compatible, they can introduce new features or behavioral changes that might require additional testing, making this option less suitable if the team's primary goal is to restrict changes strictly to non-breaking patch fixes.
- ✗
version = ">= 1.2.0"
Why it's wrong here
This constraint is highly permissive, allowing Terraform to use any module version that is 1.2.0 or newer. Critically, this includes major version updates (e.g., 2.0.0, 3.0.0), which are explicitly designed to introduce breaking changes and incompatibilities. Automatically upgrading to a new major version without thorough review and testing poses a significant risk of infrastructure failures, making this an unsafe choice for production environments.
- ✓
version = "~> 1.2"
Why this is correct
This "pessimistic" version constraint is the most appropriate choice for allowing only patch-level updates. It specifies that the module version must be greater than or equal to 1.2.0 but strictly less than 1.3.0 (i.e., `1.2.x`). This ensures that the team receives essential bug fixes and security patches (e.g., 1.2.1, 1.2.5) without inadvertently introducing new features or breaking changes that could arise from minor or major version increments, thus balancing stability with necessary maintenance.
Go deeper
Related to this question
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 →
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.