diff --git a/website/docs/language/expressions/strings.mdx b/website/docs/language/expressions/strings.mdx index 99eb6775d2..e590c9380d 100644 --- a/website/docs/language/expressions/strings.mdx +++ b/website/docs/language/expressions/strings.mdx @@ -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 + 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. + + ```hcl - example = jsonencode({ - a = 1 - b = "hello" - }) +example = jsonencode({ + a = 1 + b = "hello" +}) ``` + + + ### Indented Heredocs The standard heredoc form (shown above) treats all space characters as literal