Website: Add map example to templatefile function docs (#26126)
This change adds an example of using a map with a few keys and shows how it runs it. Co-authored-by: Nick Fagerlund <nick@hashicorp.com>
This commit is contained in:
parent
b8b6cae8ef
commit
6f9ce7310c
|
@ -49,6 +49,8 @@ to render templates while respecting resource dependencies.
|
|||
|
||||
## Examples
|
||||
|
||||
### Lists
|
||||
|
||||
Given a template file `backends.tmpl` with the following content:
|
||||
|
||||
```
|
||||
|
@ -66,6 +68,34 @@ backend 10.0.0.2:8080
|
|||
|
||||
```
|
||||
|
||||
### Maps
|
||||
|
||||
Given a template file `config.tmpl` with the following content:
|
||||
|
||||
```
|
||||
%{ for config_key, config_value in config }
|
||||
set ${config_key} = ${config_value}
|
||||
%{ endfor ~}
|
||||
```
|
||||
|
||||
The `templatefile` function renders the template:
|
||||
|
||||
```
|
||||
> templatefile(
|
||||
"${path.module}/backends.tmpl",
|
||||
{
|
||||
config = {
|
||||
"x" = "y"
|
||||
"foo" = "bar"
|
||||
"key" = "value"
|
||||
}
|
||||
}
|
||||
)
|
||||
set foo = bar
|
||||
set key = value
|
||||
set x = y
|
||||
```
|
||||
|
||||
### Generating JSON or YAML from a template
|
||||
|
||||
If the string you want to generate will be in JSON or YAML syntax, it's
|
||||
|
|
Loading…
Reference in New Issue