github.com/hashicorp/packer@v1.14.3/website/content/guides/hcl/index.mdx (about) 1 --- 2 page_title: Getting started configuring Packer with HCL2 files 3 description: >- 4 Use the HCL2 syntax for your Packer templates. Learn about arguments and blocks, comments, and multi-line strings. 5 --- 6 7 # Introduction to Packer HCL2 8 9 @include 'guides/hcl2-beta-note.mdx' 10 11 It is not necessary to know all of the details of the HCL syntax in order to 12 use Packer, and so this page summarizes the most important details to get you 13 started. If you are interested, you can find a [full definition of HCL 14 syntax](https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md) in 15 the HCL native syntax specification. 16 17 ## Arguments and Blocks 18 19 The HCL syntax is built around two key syntax constructs: arguments and blocks. 20 21 ```hcl 22 # block 23 source "amazon-ebs" "example" { 24 25 # argument 26 ami_name = "abc123" 27 } 28 ``` 29 30 ## Comments 31 32 The HCL language supports three different syntaxes for comments: 33 34 - `#` begins a single-line comment, ending at the end of the line. 35 - `//` also begins a single-line comment, as an alternative to `#`. 36 - `/*` and `*/` are start and end delimiters for a comment that might 37 span over multiple lines. 38 39 ## Multi-line strings 40 41 A multi-line string value can be provided using heredoc syntax. 42 43 ```hcl 44 variable "long_key" { 45 type = "string" 46 default = <<EOF 47 This is a long key. 48 Running over several lines. 49 It could be super handy for a boot_command. 50 EOF 51 } 52 ``` 53 54 ## Building blocks can be split in files 55 56 Currently Packer offers the `source` and the `build` root blocks. These two 57 building blocks can be defined in any order and a `build` can import one or more 58 `source`. Usually a `source` defines what we currently call a builder and a 59 `build` can apply multiple provisioning steps to a source. For example: 60 61 ```hcl 62 # folder/sources.pkr.hcl 63 source "amazon-ebs" "example-1" { 64 ami_name = "example-1-ami" 65 } 66 67 source "virtualbox-iso" "example-2" { 68 boot_command = <<EOF 69 <esc><esc><enter><wait> 70 /install/vmlinuz noapic 71 ... 72 EOF 73 } 74 ``` 75 76 ```hcl 77 # folder/build.pkr.hcl 78 build { 79 sources = [ 80 "source.amazon-ebs.example-1", 81 "source.virtualbox-iso.example-2" 82 ] 83 84 provisioner "shell" { 85 inline = [ 86 "echo 'it is alive !'" 87 ] 88 } 89 } 90 ```