Exercise 3: Variables vs. Locals — The Practical Difference — Possible Solution ==================================================================== A VARIABLE is an INPUT -- a value that comes from OUTSIDE the configuration: a `.tfvars` file, a `-var` flag, an environment variable, or a default the configuration itself supplies but which callers are free to override. It represents something the person or system running Terraform gets to choose. A LOCAL is an internal COMPUTED value -- it isn't set from outside at all; it exists purely to give a name to an expression that's used more than once, so the configuration doesn't repeat the same interpolation logic in multiple places. Nothing outside the configuration can ever override a local's value; it's fully determined by the configuration's own logic (which may itself reference variables). When to use each, concretely: - Use a VARIABLE for anything that genuinely needs to differ between runs or environments without editing the configuration file itself -- e.g. `environment` ("dev"/"staging"/"prod"), `instance_count`, or a region -- exactly the kind of value Chapter 8's separate `dev.tfvars`/`prod.tfvars` files will supply per environment. - Use a LOCAL for a value that's DERIVED from other values (often variables) and reused several times -- e.g. `local.name_prefix = "${var.environment}-${var.project}"`, computed once and referenced everywhere a consistent naming prefix is needed, rather than repeating that same interpolation expression in every resource block and risking the strings drifting out of sync if one copy is edited and another is missed. WHY THIS WORKS AS AN ANSWER ------------------------------ This states the core distinction correctly (external input that can be overridden vs. an internal, derived, non-overridable computed value) and gives one concrete example of each drawn directly from the chapter's own material, rather than a vague "variables are for settings, locals are for other stuff" gloss.