docs: Warn about use of heredoc for JSON/YAML (#37084)

* docs: Warn about use of heredoc for JSON/YAML

* move block near the end of the section
pull/32955/head
Radek Simko 9 months ago committed by GitHub
parent 44ae7da18e
commit 3ab58cd603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -47,7 +47,7 @@ There are also two special escape sequences that do not use backslashes:
## Heredoc Strings
Terraform also supports a "heredoc" style of string literal inspired by Unix
Terraform supports a "heredoc" style of string literal inspired by Unix
shell languages, which allows multi-line strings to be expressed more clearly.
```hcl
@ -74,20 +74,25 @@ In the above example, `EOT` is the identifier selected. Any identifier is
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".
### Generating JSON or YAML
<Highlight>
Don't use "heredoc" strings to generate JSON or YAML. Instead, use
[the `jsonencode` function](/terraform/language/functions/jsonencode) or
[the `yamlencode` function](/terraform/language/functions/yamlencode) so that Terraform
can be responsible for guaranteeing valid JSON or YAML syntax.
<CodeBlockConfig>
```hcl
example = jsonencode({
a = 1
b = "hello"
})
example = jsonencode({
a = 1
b = "hello"
})
```
</CodeBlockConfig>
</Highlight>
### Indented Heredocs
The standard heredoc form (shown above) treats all space characters as literal

Loading…
Cancel
Save