mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-01-02 04:01:13 -05:00
1.1 KiB
1.1 KiB
layout, page_title, sidebar_current, description
| layout | page_title | sidebar_current | description |
|---|---|---|---|
| functions | element - Functions - Configuration Language | docs-funcs-collection-element | The element function retrieves a single element from a list. |
element Function
-> Note: This page is about Terraform 0.12 and later. For Terraform 0.11 and earlier, see 0.11 Configuration Language: Interpolation Syntax.
element retrieves a single element from a list.
element(list, index)
The index is zero-based. This function produces an error if used with an empty list.
Use the built-in index syntax list[index] in most cases. Use this function
only for the special additional "wrap-around" behavior described below.
Examples
> element(["a", "b", "c"], 1)
b
If the given index is greater than the length of the list then the index is "wrapped around" by taking the index modulo the length of the list:
> element(["a", "b", "c"], 3)
a