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...