local value
A name for an expression inside a configuration, declared in a locals block and read as local.<name>, which nobody outside can set.
In more detail
Use a local to compute something once, such as a name prefix or a merged map of tags, and reuse it everywhere. The difference from a variable is control: callers set variables, but a local is always derived inside. The block is plural, locals, and the reference singular, local.
Examples
locals {
name_prefix = "${var.environment}-orders"
}name = "${local.name_prefix}-db"Related terms
- input variable — A named, typed value a configuration or module takes from outside, declared in a variable block and read as var.<name>.
- Terraform expression — Anything that produces a value on the right of an equals sign: a literal, a reference, a function call, a for expression or a conditional.
- output value — A named value a configuration publishes after apply, declared in an output block, like the return value of a function.
Taught in
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform
- Resources, Data Sources And The References Between Them — HashiCorp Terraform Associate (004) Exam Prep
- Input Variables, Outputs, And Which Value Wins — HashiCorp Terraform Associate (004) Exam Prep
- Expressions And Functions: Making Configuration Compute — HashiCorp Terraform Associate (004) Exam Prep
- Sensitive Data, Ephemeral Values And Secrets From Vault — HashiCorp Terraform Associate (004) Exam Prep
- Module Scope: What Goes In, What Comes Out — HashiCorp Terraform Associate (004) Exam Prep
- Module Versions: Pin, Upgrade, Re-Initialise — HashiCorp Terraform Associate (004) Exam Prep
- Remote State With The Backend Block — HashiCorp Terraform Associate (004) Exam Prep
- The Full Mock: Sixty Minutes, Eight Areas, One Plan For The Last Week — HashiCorp Terraform Associate (004) Exam Prep