TF-004 Interact with Terraform modules Practice Question
Exhibit
Refer to the exhibit.
```hcl
module "myapp" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
}
```
After running `terraform init`, the console shows it downloaded version 3.19.0 of the module. Why did it download that version?Which version of the module was downloaded and why?
⚠ Common exam trap
Watch out — candidates often confuse the behavior of `~> 3.0` (which allows any 3.x version) with `~> 3.0.0` (which restricts to patch updates only within 3.0.x), leading them to incorrectly select option D.
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.19.0, because it is the latest version matching the constraint ~> 3.0, which allows any 3.x version.
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.
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.0.0, because ~> 3.0 only allows the exact version 3.0.0.
Why it's wrong here
This statement is incorrect because the pessimistic operator `~> 3.0` does not restrict the module to an exact version. Instead, `~> 3.0` specifies a range that includes all versions greater than or equal to 3.0.0 and strictly less than 4.0.0. An exact version match would require the equality operator, such as `version = "= 3.0.0"`, which would indeed download only that specific version.
- ✗
3.19.0, because it is the latest version and version constraints are ignored.
Why it's wrong here
This statement is incorrect because Terraform rigorously enforces version constraints for modules and providers to ensure reproducibility and stability. Ignoring version constraints would lead to unpredictable behavior, as new, potentially breaking changes could be introduced without explicit consent. Terraform always attempts to find the latest version that *satisfies* the specified constraint, rather than ignoring it.
- ✓
3.19.0, because it is the latest version matching the constraint ~> 3.0, which allows any 3.x version.
Why this is correct
This statement is correct because the pessimistic version constraint `~> 3.0` instructs Terraform to select the highest available module version that is greater than or equal to 3.0.0 but strictly less than 4.0.0. Given that 3.19.0 is the latest version within this `3.x` major release series, it is the one Terraform will download. This constraint allows for minor and patch updates while preventing unintended major version upgrades that could introduce breaking changes.
- ✗
3.0.0, because ~> 3.0 is limited to patch updates within 3.0.x.
Why it's wrong here
This statement is incorrect because the `~> 3.0` constraint allows for minor version updates within the 3.x series, not just patch updates. Specifically, `~> 3.0` permits versions like 3.1.0, 3.2.0, and so on, up to 3.x.x, as long as they remain below 4.0.0. To limit the constraint to only patch updates within 3.0.x (e.g., 3.0.1, 3.0.2), the constraint must be specified with three version segments, such as `~> 3.0.0`.
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.