website: Use a normal file-based template in example, and expand the explanation of $${thing}
This commit is contained in:
parent
db6ec472ef
commit
b61e50be13
|
@ -451,14 +451,20 @@ Terraform 0.12 and later.
|
||||||
Long strings can be managed using templates.
|
Long strings can be managed using templates.
|
||||||
[Templates](/docs/providers/template/index.html) are
|
[Templates](/docs/providers/template/index.html) are
|
||||||
[data-sources](./data-sources.html) defined by a
|
[data-sources](./data-sources.html) defined by a
|
||||||
filename and some variables to use during interpolation. They have a
|
string with interpolation tokens (usually loaded from a file) and some variables
|
||||||
computed `rendered` attribute containing the result.
|
to use during interpolation. They have a computed `rendered` attribute
|
||||||
|
containing the result.
|
||||||
|
|
||||||
A template data source looks like:
|
A template data source looks like:
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
# templates/greeting.tpl
|
||||||
|
${hello} ${world}!
|
||||||
|
```
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
data "template_file" "example" {
|
data "template_file" "example" {
|
||||||
template = "$${hello} $${world}!"
|
template = "${file("templates/greeting.tpl")}"
|
||||||
vars {
|
vars {
|
||||||
hello = "goodnight"
|
hello = "goodnight"
|
||||||
world = "moon"
|
world = "moon"
|
||||||
|
@ -472,7 +478,12 @@ output "rendered" {
|
||||||
|
|
||||||
Then the rendered value would be `goodnight moon!`.
|
Then the rendered value would be `goodnight moon!`.
|
||||||
|
|
||||||
Note that the double dollar signs (`$$`) are needed in inline templates. Otherwise Terraform will return an error.
|
-> **Note:** If you specify the template as a literal string instead of loading
|
||||||
|
a file, the inline template must use double dollar signs (like `$${hello}`) to
|
||||||
|
prevent Terraform from interpolating values from the configuration into the
|
||||||
|
string. This is because `template_file` creates its own instance of the
|
||||||
|
interpolation system, with values provided by its nested `vars` block instead of
|
||||||
|
by the surrounding scope of the configuration.
|
||||||
|
|
||||||
You may use any of the built-in functions in your template. For more
|
You may use any of the built-in functions in your template. For more
|
||||||
details on template usage, please see the
|
details on template usage, please see the
|
||||||
|
|
Loading…
Reference in New Issue