You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/website/content/docs/templates/hcl_templates/functions/collection/coalesce.mdx

40 lines
1.3 KiB

---
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.
---
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!IMPORTANT]
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
# `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.