website: Recommend against making JSON/YAML with heredocs
This is a repeated cause of confusion and questions in the community forum, because both JSON and YAML valid syntax are hard to generate using just string concatenation. Terraform has built-in functions for both of these common serializations to avoid those problems, and so this will hopefully make these better alternatives more discoverable.
This commit is contained in:
parent
ab1dd87540
commit
776b33db32
|
@ -72,6 +72,20 @@ In the above example, `EOT` is the identifier selected. Any identifier is
|
||||||
allowed, but conventionally this identifier is in all-uppercase and begins with
|
allowed, but conventionally this identifier is in all-uppercase and begins with
|
||||||
`EO`, meaning "end of". `EOT` in this case stands for "end of text".
|
`EO`, meaning "end of". `EOT` in this case stands for "end of text".
|
||||||
|
|
||||||
|
### Generating JSON or YAML
|
||||||
|
|
||||||
|
Don't use "heredoc" strings to generate JSON or YAML. Instead, use
|
||||||
|
[the `jsonencode` function](../functions/jsonencode.html) or
|
||||||
|
[the `yamlencode` function](../functions/yamlencode.html) so that Terraform
|
||||||
|
can be responsible for guaranteeing valid JSON or YAML syntax.
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
example = jsonencode({
|
||||||
|
a = 1
|
||||||
|
b = "hello"
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### Indented Heredocs
|
### Indented Heredocs
|
||||||
|
|
||||||
The standard heredoc form (shown above) treats all space characters as literal
|
The standard heredoc form (shown above) treats all space characters as literal
|
||||||
|
|
Loading…
Reference in New Issue