Back to Packer

`indent` Function

website/content/docs/templates/hcl_templates/functions/string/indent.mdx

1.15.31.1 KB
Original Source

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

[!IMPORTANT]
Documentation Update: Product documentation previously located in /website has moved to the hashicorp/web-unified-docs repository, where all product documentation is now centralized. Please make contributions directly to web-unified-docs, since changes to /website in this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

indent Function

indent adds a given number of spaces to the beginnings of all but the first line in a given multi-line string.

hcl
indent(num_spaces, string)

Examples

This function is useful for inserting a multi-line string into an already-indented context in another string:

shell-session
> "  items: %{indent(2, "[\n  foo,\n  bar,\n]\n")}"
  items: [
    foo,
    bar,
  ]

The first line of the string is not indented so that, as above, it can be placed after an introduction sequence that has already begun the line.