Courseiva
Interact with Terraform moduleseasyMultiple ChoiceObjective-mapped

How to Use ~> Version Constraints in Terraform Modules

A team is using a module from the Terraform Registry and wants to ensure they always get the latest patch version of the 3.2.x series. Which version constraint should they use?

Quick Answer

The answer is ~> 3.2.0 because the pessimistic operator with three numeric parts locks the constraint to only patch-level updates within the 3.2.x series, allowing versions like 3.2.1 or 3.2.5 but blocking any minor or major bumps. This works because Terraform interprets the tilde-greater-than symbol as “allow the rightmost specified segment to increment,” so ~> 3.2.0 permits changes only to the patch digit. On the HashiCorp Terraform Associate TF-003 exam, this question tests your understanding of version constraint syntax and the critical difference between two-part and three-part pessimistic constraints—a common trap is confusing ~> 3.2 (which allows minor updates to 3.3) with ~> 3.2.0 (which does not). To remember, think of the three-part constraint as a “patch-only cage”: the extra zero locks the minor version in place, so only the last number can move.

⚠ Common exam trap

A common trap in Terraform is confusing the `~>` operator with two versus three numbers. `~> 3.2` allows minor version updates (e.g., 3.3, 3.4), while `~> 3.2.0` restricts updates to only patch versions (e.g., 3.2.1, 3.2.2). Candidates often mistakenly choose `~> 3.2` thinking it constrains to the 3.2.x series, but it actually allows any 3.x version.

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

~> 3.2.0

The `~>` (pessimistic constraint) operator in Terraform allows only the rightmost version component to increment. For `~> 3.2.0`, this means any version >= 3.2.0 and < 3.3.0, which precisely matches the requirement for the latest patch within the 3.2.x series. Option C is correct because it locks the major and minor versions while permitting patch-level updates.

Answer analysis

Option-by-option breakdown

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

  • ~> 3.2

    Why it's wrong here

    This allows minor version updates (e.g., 3.3.0), not just patches.

  • 3.2.*

    Why it's wrong here

    This is not a valid Terraform version constraint syntax.

  • ~> 3.2.0

    Why this is correct

    This allows only patch-level increments within 3.2.x (e.g., 3.2.0 to 3.2.1).

  • >= 3.2, < 4.0

    Why it's wrong here

    This also allows minor version updates, which is broader than required.

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

Same concept, more angles

2 more ways this is tested on TF-004

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which version of the module was downloaded and why?

easy
  • A.3.0.0, because ~> 3.0 only allows the exact version 3.0.0.
  • B.3.19.0, because it is the latest version and version constraints are ignored.
  • C.3.19.0, because it is the latest version matching the constraint ~> 3.0, which allows any 3.x version.
  • D.3.0.0, because ~> 3.0 is limited to patch updates within 3.0.x.

Why C: The constraint `~> 3.0` in Terraform's version constraint syntax allows only the rightmost element to increment. Since `3.0` is a two-part version, the constraint permits any version in the `3.x` range (i.e., `3.0.0` up to but not including `4.0.0`). Therefore, the latest version matching that constraint is `3.19.0`, which is the highest available 3.x version.

Variation 2. 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?

easy
  • A.version = "= 1.2.0"
  • B.version = ">= 1.2.0, < 2.0.0"
  • C.version = ">= 1.2.0"
  • D.version = "~> 1.2"

Why D: 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.

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.