This site contains affiliate links and we may earn a commission at no extra cost to you. Learn more.

Terraform variables, outputs and locals explained

Updated September 6, 2026

Input variables, outputs and locals in Terraform: what each does, when to use them, how values are set, and how they appear on the Terraform Associate 004 exam.

Input variables, outputs and locals are how you make Terraform configurations flexible and reusable. The 004 tests all three, and the differences are simple once you see them side by side.

Input variables: your parameters

Declared with a variable block, input variables are the parameters you pass into a configuration or module. They can have a type, a default, a description, a validation condition, and a sensitive flag that hides the value in output.

How variable values are set (and the precedence)

Terraform collects variable values from several places, and later sources win:

  • Defaults in the variable block (lowest priority)
  • Environment variables named TF_VAR_name
  • terraform.tfvars and *.auto.tfvars files
  • The command line: -var and -var-file (highest priority)

Knowing this precedence order is a classic exam question.

Outputs: exposing values

An output block returns a value to the user after apply, or to a parent module that called this one. Outputs are the only way a calling module reads values from a child module, and they can also be marked sensitive.

Locals: named expressions

A locals block assigns a name to an expression so you can compute something once and reuse it, keeping configuration DRY. Unlike variables, locals are not set from outside — they are internal helpers. Use them for derived values and repeated expressions.

Quick contrast

ConstructSet from outside?Purpose
Input variableYesParameterise the configuration
LocalNoName and reuse an internal expression
OutputNo (it returns)Expose a value to the user or parent module

Practise declaring all three in one small config, then check yourself against the objectives checklist.

Ready to start studying?

Related guides