github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/element.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "element - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-collection-element" 5 description: |- 6 The element function retrieves a single element from a list. 7 --- 8 9 # `element` Function 10 11 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 12 earlier, see 13 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 14 15 `element` retrieves a single element from a list. 16 17 ```hcl 18 element(list, index) 19 ``` 20 21 The index is zero-based. This function produces an error if used with an 22 empty list. 23 24 Use the built-in index syntax `list[index]` in most cases. Use this function 25 only for the special additional "wrap-around" behavior described below. 26 27 ## Examples 28 29 ``` 30 > element(["a", "b", "c"], 1) 31 b 32 ``` 33 34 If the given index is greater than the length of the list then the index is 35 "wrapped around" by taking the index modulo the length of the list: 36 37 ``` 38 > element(["a", "b", "c"], 3) 39 a 40 ``` 41 42 ## Related Functions 43 44 * [`index`](./index.html) finds the index for a particular element value. 45 * [`lookup`](./lookup.html) retrieves a value from a _map_ given its _key_.