CertLumen

HashiCorp Terraform Associate (004) · Section 4 · 24% of the exam

Use variables and outputs

One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform configuration”. Here is what it covers, the points to remember and a question to try.

What it covers

Input variables parameterize a module, locals name intermediate values, and outputs publish results. This lesson covers variable arguments, validation, how Terraform picks a value when several sources set the same variable, sensitive and ephemeral values, and how outputs are read.

Points to remember

  • Variables are inputs (var.x), locals are private names (local.x), outputs are results.
  • A variable with no default is required; the default must be a literal.
  • Precedence low to high: default, TF_VAR_, terraform.tfvars, terraform.tfvars.json, *.auto.tfvars, then -var / -var-file.
  • validation blocks need a boolean condition and an error_message; since 1.9 they can refer to other objects.
  • sensitive = true redacts output but the value is still in state; ephemeral = true (1.10+) keeps it out of plan and state.

Try a question

An engineer has a variable that must be a TCP port between 1024 and 65535, and wants a clear message at plan time. Which construct is designed for this?

  1. AA lifecycle block with a custom condition on every resource that uses the port
  2. BA check block that runs after apply and reports the port problem as a warning
  3. Cnullable = false on the variable so that a null port is rejected for the range
  4. DA validation block with a condition in the variable
Show the answer

D. A variable validation block evaluates a boolean condition on the input while planning and returns your error message when it is false.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Input variables, locals and outputs teaches this objective (about 40 minutes), and 18 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 37 objectives · Next objective →