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

Simplifying your template with variables

Variables can be declared in HCL2 in a very similar way to how Terraform declares variables: create a variable block, give it a name, give it a description and type (optional), and specify an optional default value. Here, we will create a variable called iso that defaults to a download URL. This may be referenced in the code directly as var.iso or it can be used with standard shell interpolation in strings, as in ${var.creds.user}, which helps with templating:

variable "iso" {
  description = "The path to your ISO."
  type = string
  default = "https://fqdn/media/base.iso"
}

Local variables differ from normal variables in that they can’t be assigned as parameters. Locals offer a simple way to declare reusable values in your code without allowing the runner to specify them as parameters. You can think of variables as public parameters and locals as private variables, which...

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