---
page_title: coalesce function reference
description: |-
  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.
---

# `coalesce` Function

`coalesce` takes any number of arguments and returns the first one
that isn't null or an empty string.

## Examples

```shell-session
> coalesce("a", "b")
a
> coalesce("", "b")
b
> coalesce(1,2)
1
```

To perform the `coalesce` operation with a list of strings, use the `...`
symbol to expand the list as arguments:

```shell-session
> coalesce(["", "b"]...)
b
```

## Related Functions

- [`coalescelist`](/packer/docs/templates/hcl_templates/functions/collection/coalescelist) performs a similar operation with
  list arguments rather than individual arguments.
