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.
terraform/website/docs/language/functions/lookup.mdx

37 lines
1.3 KiB

---
page_title: lookup - Functions - Configuration Language
description: The lookup function retrieves an element value from a map given its key.
---
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!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.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
# `lookup` Function
`lookup` retrieves the value of a single element from a map, given its key.
If the given key does not exist, the given default value is returned instead.
```hcl
lookup(map, key, default)
```
-> For historical reasons, the `default` parameter is actually optional. However,
omitting `default` is deprecated since v0.7 because that would then be
equivalent to the native index syntax, `map[key]`.
## Examples
```
> lookup({a="ay", b="bee"}, "a", "what?")
ay
> lookup({a="ay", b="bee"}, "c", "what?")
what?
```
## Related Functions
* [`element`](/terraform/language/functions/element) retrieves a value from a _list_ given its _index_.