locals
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.
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
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |