Courseiva
Read, generate and modify configurationeasyMultiple ChoiceObjective-mapped

TF-004 Read, generate and modify configuration Practice Question

In Terraform, which block is used to define a default value for a variable that can be overridden at runtime?

⚠ Common exam trap

Watch out — candidates often confuse `locals` with `variable` because both can hold values, but only `variable` supports runtime override via external inputs, whereas `locals` are purely internal and immutable after plan generation.

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

variable

In Terraform, the `variable` block is used to declare input variables, which can include a `default` argument to specify a fallback value. This default can be overridden at runtime using mechanisms like `-var` flags, `TF_VAR_` environment variables, or `.tfvars` files, making option B correct.

Answer analysis

Option-by-option breakdown

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

  • locals

    Why it's wrong here

    The `locals` block is used to define named values that can be referenced elsewhere in the Terraform configuration. These values are computed from other expressions or literals within the configuration itself, acting as convenient aliases or intermediate calculations. However, `locals` cannot accept external input directly nor do they support a `default` argument for user-defined variables; they are derived, not declared as inputs.

  • variable

    Why this is correct

    The `variable` block is specifically designed to declare input variables for a Terraform module. Within this block, the `default` argument allows you to specify a fallback value that will be used if no explicit value is provided for the variable through other means, such as command-line arguments, environment variables, or `.tfvars` files. This mechanism ensures that the configuration can proceed even without user input for optional parameters.

  • output

    Why it's wrong here

    The `output` block is used to define values that are exposed by a Terraform module, making them accessible to parent modules or for display to the user after `terraform apply`. These values represent the results or attributes of resources provisioned by the configuration. Unlike `variable` blocks, `output` blocks do not accept input or define default values; they solely present computed information.

  • terraform

    Why it's wrong here

    The `terraform` block specifies global settings and configuration for Terraform itself, rather than defining specific infrastructure components or input parameters. It is used to declare required providers, define backend configurations for state storage, and set the minimum required Terraform version. This block does not support defining variables or their default values; its scope is entirely foundational to the Terraform CLI's operation.

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 →

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.