4.3. Variables and Outputs
💡 First Principle: Variables are a module's inputs and outputs are its return values — treating a Terraform module like a function (inputs in, results out) explains variable scope, output visibility, and why locals sit privately in between.
Why care: Variables and outputs are the interface of every reusable module and appear constantly. The exam tests variable types/validation, sensitivity, precedence of variable sources, and the role of outputs in exposing data.
The mental model: A module is a function. variable blocks are the parameters, output blocks are the return statement, and locals are private intermediate variables used inside the body.
⚠️ Common Misconception: "Locals and variables are the same thing." Input variables receive values from outside the module (CLI, tfvars, defaults); locals are computed inside the module and can't be set externally. They serve opposite directions of data flow.