Interview Prep/Terraform/Resources Variables and Expressions

A teammate puts everything in `variables.tf`, including values computed from other variables. What's the right place for computed values?

BeginnerScenarioResources Variables and Expressions
Answer

Situation read → Confusion between inputs and internal values.

What I'd do → Keep caller-supplied inputs in variable blocks and derived values in locals.

locals {
  name_prefix = "${var.project}-${var.environment}"
  common_tags = merge(var.tags, { Project = var.project })
}

Why → Variables form the module's public interface and can be overridden; locals are private, can't be set from outside, and remove repeated expressions.

Interview tip → A new reader should learn the interface from variables.tf and outputs.tf alone.

All Terraform questions Roadmap: Terraform

More on Resources Variables and Expressions