From 6f9ce7310cb6a980aa23a6aff13240dc2f0e2218 Mon Sep 17 00:00:00 2001 From: "Jon \"The Nice Guy\" Spriggs" Date: Wed, 9 Sep 2020 20:30:06 +0100 Subject: [PATCH] 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 --- .../functions/templatefile.html.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/website/docs/configuration/functions/templatefile.html.md b/website/docs/configuration/functions/templatefile.html.md index 55756bed9b..5dd832105a 100644 --- a/website/docs/configuration/functions/templatefile.html.md +++ b/website/docs/configuration/functions/templatefile.html.md @@ -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