kb/variables
Terraform variables, outputs, and locals: a variable block takes input (CLI -var, env TF_VAR_*, .tfvars, default). An output block exposes values for reuse elsewhere. Locals are computed internal names. This is the grammar of any config beyond hello-world.
.tfvars files hold variable values in HCL or JSON format. terraform.tfvars and *.auto.tfvars are loaded automatically; all others require -var-file. This is the main mechanism for separating code from environment configuration.
locals is a block with names visible only inside HCL (not input, not output). Useful for DRY: compute a common prefix or tag set once, then use it everywhere via local.x. Do not confuse with variable (input) and output (output).
An output is a value that Terraform displays after apply and stores in state. Use it to (a) show the user the ID or ARN of a created resource, (b) pass values between modules, or (c) feed values to scripts via `terraform output -raw`.
A variable is a parameter that receives its value from outside the configuration (CLI, environment variable, .tfvars file). You declare it in HCL with type, default, description, and validation, then reference it as var.name. Variables remove hardcoded values and let one HCL configuration serve multiple environments.
Six sources, in priority order: -var in CLI > -var-file > *.auto.tfvars (alphabetically) > terraform.tfvars > TF_VAR_* env > default. If none of these supply a value, Terraform prompts interactively. Understanding this order matters for CI/CD.