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:
Jon "The Nice Guy" Spriggs 2020-09-09 20:30:06 +01:00 committed by GitHub
parent b8b6cae8ef
commit 6f9ce7310c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -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