d1e139c3fb
Add more detailed HCL2 docs, mostly lifted from Packer with tweaks for Nomad. The function docs are basically verbatim taken from Packer with basic string substitutions. I commented out some for_each details as the examples are mostly driven towards Packer resources. I'll iterate on those with better Nomad examples.
54 lines
1.7 KiB
Plaintext
54 lines
1.7 KiB
Plaintext
---
|
|
layout: docs
|
|
page_title: Local Values - HCL Configuration Language
|
|
sidebar_title: Locals
|
|
description: >-
|
|
Local values assign a name to an expression that can then be used multiple
|
|
times within a folder.
|
|
---
|
|
|
|
# Local Values
|
|
|
|
`@include 'beta-nomad1.0-note.mdx'`
|
|
|
|
Local values assign a name to an expression, that can then be used multiple
|
|
times within a folder.
|
|
|
|
If [variables](/docs/job-specification/hcl2/variables) are analogous to function arguments then
|
|
_local values_ are comparable to a function's local variables.
|
|
|
|
## Examples
|
|
|
|
Local values are defined in `locals` blocks:
|
|
|
|
```hcl
|
|
# A computed default name prefix
|
|
locals {
|
|
default_name_prefix = "${var.project_name}-web"
|
|
name_prefix = "${var.name_prefix != "" ? var.name_prefix : local.default_name_prefix}"
|
|
}
|
|
|
|
# Local values can be interpolated elsewhere using the "local." prefix.
|
|
job "${local.name_prefix}_loadbalancer" {
|
|
# ...
|
|
}
|
|
```
|
|
|
|
## Description
|
|
|
|
The `locals` block defines one or more local variables.
|
|
|
|
The names given for the items in the `locals` block must be unique. The given
|
|
value can be any expression that is valid within the current file.
|
|
|
|
The expression of a local value can refer to other locals, but reference cycles
|
|
are not allowed. That is, a local cannot refer to itself or to a variable that
|
|
refers (directly or indirectly) back to it.
|
|
|
|
It's recommended to group together logically-related local values into a single
|
|
block, particularly if they depend on each other. This will help the reader
|
|
understand the relationships between variables. Conversely, prefer to define
|
|
_unrelated_ local values in _separate_ blocks, and consider annotating each
|
|
block with a comment describing any context common to all of the enclosed
|
|
locals.
|