website/content/guides/hcl/index.mdx
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
[!IMPORTANT]
Documentation Update: Product documentation previously located in/websitehas moved to thehashicorp/web-unified-docsrepository, where all product documentation is now centralized. Please make contributions directly toweb-unified-docs, since changes to/websitein this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
@include 'guides/hcl2-beta-note.mdx'
It is not necessary to know all of the details of the HCL syntax in order to use Packer, and so this page summarizes the most important details to get you started. If you are interested, you can find a full definition of HCL syntax in the HCL native syntax specification.
The HCL syntax is built around two key syntax constructs: arguments and blocks.
# block
source "amazon-ebs" "example" {
# argument
ami_name = "abc123"
}
The HCL language supports three different syntaxes for comments:
# begins a single-line comment, ending at the end of the line.// also begins a single-line comment, as an alternative to #./* and */ are start and end delimiters for a comment that might
span over multiple lines.A multi-line string value can be provided using heredoc syntax.
variable "long_key" {
type = "string"
default = <<EOF
This is a long key.
Running over several lines.
It could be super handy for a boot_command.
EOF
}
Currently Packer offers the source and the build root blocks. These two
building blocks can be defined in any order and a build can import one or more
source. Usually a source defines what we currently call a builder and a
build can apply multiple provisioning steps to a source. For example:
# folder/sources.pkr.hcl
source "amazon-ebs" "example-1" {
ami_name = "example-1-ami"
}
source "virtualbox-iso" "example-2" {
boot_command = <<EOF
<esc><esc><enter><wait>
/install/vmlinuz noapic
...
EOF
}
# folder/build.pkr.hcl
build {
sources = [
"source.amazon-ebs.example-1",
"source.virtualbox-iso.example-2"
]
provisioner "shell" {
inline = [
"echo 'it is alive !'"
]
}
}