docs: fixup HCL2 index collection function documentation. (#13511)

This commit is contained in:
James Rasell
2022-06-28 18:27:38 +02:00
committed by GitHub
parent 37e5accf09
commit c635ae0f89

View File

@@ -1,25 +1,30 @@
---
layout: docs
page_title: index - Functions - Configuration Language
description: The index function finds the element index for a given value in a list.
description: |-
The index function returns an element from the given list or map
using the given index or key.
---
# `index` Function
`index` finds the element index for a given value in a list.
`index` finds the element at the index when handling lists, or the element at
the key when handling maps.
```hcl
index(list, value)
```
The returned index is zero-based. This function produces an error if the given
value is not present in the list.
## Examples
```shell-session
> index(["a", "b", "c"], "b")
1
> index(["a", "b", "c"], 1)
"b"
```
```shell-session
> index({"a"=1, "c"=2, "d"=3}, "c")
2
```
## Related Functions