DELAPARRA
Index
Color
NL
Category: Terraform

heredoc

Explained by Updated

What is heredoc?

heredoc: A multi-line string literal. Use <<-EOT (with the dash) to strip leading indentation. A heredoc is a way to write a multi-line string in Terraform, as in many shell and programming languages. It starts with <<EOT, ends with EOT on its own line, and everything in between is the string.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about heredoc

How is heredoc used in practice?

It is often used for start-up scripts, inline policies or configuration files that a resource needs as text. The dashed form, <<-EOT, strips leading indentation, so the content can be indented neatly inside your code.

What should you keep in mind with heredoc?

For anything longer than a few lines, consider putting the content in a separate file and loading it with file() or templatefile(). Then editors can highlight it properly, and JSON or YAML can be validated on its own. For JSON policies, jsonencode() on a Terraform map is safer than a heredoc, because it guarantees valid JSON.

What does an example of heredoc look like?

user_data = <<-EOT #!/bin/bash echo hello EOT

At a glance

CategoryTerraform
Explained by
Updated

More Terraform terms

All terms starting with H

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.