Courseiva

TF-004 Interact with Terraform modules Practice Question

A module 'web_app' defines an input variable 'instance_count' with type = number and a validation block ensuring it is between 1 and 10. What happens if a user sets instance_count = 0?

⚠ Common exam trap

Candidates often assume HashiCorp Terraform silently falls back to a default value or ignores validation when a variable is explicitly set, but in reality, explicit assignment overrides defaults and validation is always enforced, causing an immediate error for out-of-range values.

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 returns an error during validation and stops execution.

HashiCorp Terraform validates input variables against their declared type and any validation blocks before applying configuration. When `instance_count = 0` is set, the validation block's condition `var.instance_count >= 1 && var.instance_count <= 10` evaluates to `false`, causing HashiCorp Terraform to halt with an error during the `terraform plan` or `terraform validate` phase, preventing any further execution.

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 returns an error during validation and stops execution.

    Why this is correct

    When a variable's custom validation condition fails, Terraform immediately halts execution and returns an error. This occurs during the planning phase (e.g., `terraform plan` or `terraform apply`), before any infrastructure changes are proposed or applied. The explicit error message defined in the validation block provides clear feedback, preventing the deployment of invalid configurations.

  • ✗

    Terraform applies the module with zero instances, as a value of 0 is allowed.

    Why it's wrong here

    Terraform will not apply the module with zero instances because the validation block explicitly defines a condition that rejects a value of 0. Even if 0 is a numerically valid integer, the custom validation rule overrides this, making it an invalid input for this specific `instance_count` variable. The validation ensures that only values meeting the defined criteria are accepted.

  • ✗

    Terraform ignores the validation if the variable is explicitly set.

    Why it's wrong here

    Terraform's variable validation mechanism is a fundamental check on the integrity and suitability of the variable's value, regardless of its source. Whether a variable is explicitly set via a `.tfvars` file, command-line argument, or environment variable, the validation block will still be evaluated. This ensures consistent data quality and prevents misconfigurations, irrespective of how the input was provided.

  • ✗

    Terraform uses the default value for instance_count from the module.

    Why it's wrong here

    Terraform does not fall back to a default value if a provided input fails validation. The validation process occurs on the value that is *intended* to be used, whether it was explicitly provided or would otherwise default. If the provided value is invalid according to the validation rules, Terraform immediately errors out, rather than attempting to substitute a default value, which might itself be subject to different validation or lead to unexpected behavior.

About these practice questions

Courseiva writes every TF-004 question from scratch — 434 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 →

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.