--- page_title: Strings and Templates - Configuration Language description: >- String literals and template sequences interpolate values and manipulate text. Learn about both quoted and heredoc string syntax. --- # Strings and Templates String literals are the most complex kind of literal expression in Terraform, and also the most commonly used. Terraform supports both a quoted syntax and a "heredoc" syntax for strings. Both of these syntaxes support template sequences for interpolating values and manipulating text. ## Quoted Strings A quoted string is a series of characters delimited by straight double-quote characters (`"`). ``` "hello" ``` ### Escape Sequences In quoted strings, the backslash character serves as an escape sequence, with the following characters selecting the escape behavior: | Sequence | Replacement | | ------------ | ----------------------------------------------------------------------------- | | `\n` | Newline | | `\r` | Carriage Return | | `\t` | Tab | | `\"` | Literal quote (without terminating the string) | | `\\` | Literal backslash | | `\uNNNN` | Unicode character from the basic multilingual plane (NNNN is four hex digits) | | `\UNNNNNNNN` | Unicode character from supplementary planes (NNNNNNNN is eight hex digits) | There are also two special escape sequences that do not use backslashes: | Sequence | Replacement | | -------- | -------------------------------------------------------------- | | `$${` | Literal `${`, without beginning an interpolation sequence. | | `%%{` | Literal `%{`, without beginning a template directive sequence. | ## Heredoc Strings Terraform also supports a "heredoc" style of string literal inspired by Unix shell languages, which allows multi-line strings to be expressed more clearly. ```hcl <}`/`%{else}`/`%{endif}` directive chooses between two templates based on the value of a bool expression: ```hcl "Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!" ``` The `else` portion may be omitted, in which case the result is an empty string if the condition expression returns `false`. - The `%{for in }` / `%{endfor}` directive iterates over the elements of a given collection or structural value and evaluates a given template once for each element, concatenating the results together: ```hcl <