Add tip about using local instead of locals for complex cases (#11036)

* add tip about using local instead of locals

* Apply suggestions from code review

Co-authored-by: Megan Marsh <megan@hashicorp.com>

Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
Co-authored-by: Megan Marsh <megan@hashicorp.com>
This commit is contained in:
Sylvia Moss 2021-05-25 03:50:35 +02:00 committed by GitHub
parent f07813e14d
commit 69572b442a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -86,7 +86,7 @@ source "amazon-ebs" "server" {
}
```
## Description
## Single `local` block
The `local` block defines exactly one local variable within a folder. The block
label is the name of the local, and the "expression" is the expression that
@ -94,6 +94,22 @@ should be evaluated to create the local. Using this block, you can optionally
supply a "sensitive" boolean to mark the variable as sensitive and filter it
from logs.
```hcl
local "mylocal" {
expression = "${var.secret_api_key}"
sensitive = true
}
```
This block is also very useful for defining complex locals. Packer might take some time to expand and evaluate `locals`
with complex expressions dependent on other locals. The `locals` block is read as a map. Maps are not sorted, and therefore
the evaluation time is not deterministic.
To avoid that, singular `local` blocks should be used instead. These will be
evaluated in the order they are defined, and the evaluation order and time will always be the same.
## `locals` block
The `locals` block defines one or more local variables within a folder.
The names given for the items in the `locals` block must be unique throughout a