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/lookup.mdx

27 lines
649 B

---
page_title: lookup - Functions - Configuration Language
description: The lookup function retrieves an element value from a map given its key.
---
# `lookup` Function
`lookup` retrieves the value of a single element from a map, given its key.
If the given key does not exist, a the given default value is returned instead.
```hcl
lookup(map, key, default)
```
## Examples
```shell-session
> lookup({a="ay", b="bee"}, "a", "what?")
ay
> lookup({a="ay", b="bee"}, "c", "what?")
what?
```
## Related Functions
- [`element`](/packer/docs/templates/hcl_templates/functions/collection/element) retrieves a value from a _list_ given its _index_.