page_title: coalesce - Functions - Configuration Language
page_title: coalesce function reference
description: |-
The coalesce function takes any number of arguments and returns the
first one that isn't null nor empty.
The `coalesce` function returns the first argument that is not empty or `null` from a list of arguments. Learn to use the `coalesce` function in Packer templates.
page_title: coalescelist - Functions - Configuration Language
page_title: coalescelist function reference
description: |-
The coalescelist function takes any number of list arguments and returns the
first one that isn't empty.
The `coalescelist` function returns the first non-empty argument in a list of arguments. Learn how to use the `coalescelist` function in Packer templates.
page_title: contains - Functions - Configuration Language
description: The contains function determines whether a list or set contains a given value.
page_title: contains function reference
description: The `contains` function determines whether a list or set contains a given value. Learn how to use the `contains` function in Packer templates.
page_title: lookup - Functions - Configuration Language
description: The lookup function retrieves an element value from a map given its key.
page_title: lookup function reference
description: The `lookup` function retrieves an element value from a map using the map key. Learn how to use the `lookup` function in Packer templates.
page_title: setintersection - Functions - Configuration Language
page_title: setintersection function reference
description: |-
The setintersection function takes multiple sets and produces a single set
containing only the elements that all of the given sets have in common.
The `setintersection` function creates one set from multiple sets that contains only elements common to all input sets. Learn how to use `setintersection` in Packer templates.
---
# `setintersection` Function
The `setintersection` function takes multiple sets and produces a single set
containing only the elements that all of the given sets have in common.
In other words, it computes the
[intersection](<https://en.wikipedia.org/wiki/Intersection_(set_theory)>) of the sets.
page_title: setunion - Functions - Configuration Language
page_title: setunion function reference
description: |-
The setunion function takes multiple sets and produces a single set
containing the elements from all of the given sets.
The `setunion` function creates one set containing the elements from multiple given sets. Learn how to use the `setunion` function in Packer templates.
page_title: fileexists - Functions - Configuration Language
description: The fileexists function determines whether a file exists at a given path.
page_title: fileexists function reference
description: The `fileexists` function determines whether a file exists at a given path. Learn how to use the `fileexists` function in Packer templates.
page_title: fileset - Functions - Configuration Language
description: The fileset function enumerates a set of regular file names given a pattern.
page_title: fileset function reference
description: The `fileset` function enumerates a set of regular file names according to a pattern. Learn how to use the `fileset` function in Packer templates.
page_title: templatefile - Functions - Configuration Language
page_title: templatefile function reference
description: |-
The templatefile function reads the file at the given path and renders its
content as a template using a supplied set of template variables.
The `templatefile` function reads a file and renders its
content as a template using a set of template variables. Learn how to use the `templatefile` function.
---
# `templatefile` Function
-> _Recommendation:_ we recommend using the `.pkrtpl.hcl` file extension when
using the `templatefile` function. Template files _are_ hcl treated as files but
also templates and therefore have slightly different set of features
than the ones offered in a `.pkr.hcl` Packer template. While you are not
required to use this extension, doing so will enable syntax highlighters to
properly understand your file.
`templatefile` reads the file at the given path and renders its content as a
The `templatefile` function reads the file at the given path and renders its content as a
template using a supplied set of template variables.
```hcl
templatefile(path, vars)
```
We recommend using the `.pkrtpl.hcl` file extension when using the `templatefile` function to create templates. Packer treats HCL templates as combination of file and template. As a result, HCL template files have slightly different set of features than the templates with a `.pkr.hcl` extension. Using the `.pkr.hcl` extension also enables syntax highlighters to properly understand your file.
The template syntax is the same as for string templates in the main HCL2
language, including interpolation sequences delimited with `${ ... }`. This
function just allows longer template sequences to be factored out into a