DELAPARRA
Index
Color
NL
Category: Terraform

locals

Explained by Updated

What is locals?

locals: Named local values to avoid repetition — like constants computed once and referenced as local.. locals in Terraform defines named values computed once and reused throughout the configuration, as local.name. A common example is a set of tags every resource should carry. They remove repetition and give complex expressions a readable name. Instead of repeating "${var.project}-${var.env}" in twenty places, you define local.prefix once.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about locals

What should you keep in mind with locals?

Use locals for values derived from variables and data sources, not for settings users should change; those belong in variables. Keep them near the top of a file or in a locals.tf, so readers find them easily. If a local grows into a large, nested expression, consider whether part of it should be a module or an input variable instead. terraform console lets you inspect their values.

What does an example of locals look like?

locals { common_tags = { Project = "lingo" Env = var.env } }

At a glance

CategoryTerraform
Explained by
Updated

More Terraform terms

All terms starting with L

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.