Reader small image

You're reading from  HashiCorp Packer in Production

Product typeBook
Published inJul 2023
PublisherPackt
ISBN-139781803246857
Edition1st Edition
Right arrow
Author (1)
John Boero
John Boero
author image
John Boero

John Boero has 20 years of experience in the tech industry covering engineering, consulting, architecture, and pre-sales. He comes from Chicago, IL in the USA but currently lives in London, UK. He has worked for Red Hat, Puppet, and HashiCorp and remains active in the open source community. All commissions for this book will be donated to the Raspberry Pi Foundation non-profit to encourage coding and computing skills for kids.
Read more about John Boero

Right arrow

Using templates to populate configuration resources with variables

Here is an example of HCL’s herefile or heredoc syntax, indicated by the arbitrary EOF delimiters. It may be powerful to embed complex files into one HCL file, but it can also be very hard to read later down the road. This herefile syntax is most valuable when using variables as a template. For example, here we write a multiple-line herefile to our /etc/motd file using the content option, and we include the built-in ${build.PackerRunUUID} variable so that each time someone logs in, they will be prompted with the unique build ID generated by Packer. You could also include one of your own variables or locals. Note the indentation of this syntax. The lines of a herefile in HCL are literal raw input from the beginning of each line, so if you indent your lines of text, the leading white space will be transferred to your file. This can make herefiles difficult to read in your template:

  content ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
HashiCorp Packer in Production
Published in: Jul 2023Publisher: PacktISBN-13: 9781803246857

Author (1)

author image
John Boero

John Boero has 20 years of experience in the tech industry covering engineering, consulting, architecture, and pre-sales. He comes from Chicago, IL in the USA but currently lives in London, UK. He has worked for Red Hat, Puppet, and HashiCorp and remains active in the open source community. All commissions for this book will be donated to the Raspberry Pi Foundation non-profit to encourage coding and computing skills for kids.
Read more about John Boero