mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-09 18:01:49 -04:00
Signed-off-by: Janos <86970079+janosdebugs@users.noreply.github.com> Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Signed-off-by: Roman Grinovski <roman.grinovski@gmail.com> Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
33 lines
782 B
Plaintext
33 lines
782 B
Plaintext
---
|
|
sidebar_label: lookup
|
|
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, the given default value is returned instead.
|
|
|
|
```
|
|
lookup(map, key, default)
|
|
```
|
|
|
|
:::note
|
|
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`](../../language/functions/element.mdx) retrieves a value from a _list_ given its _index_.
|