You can use terraform element() function to get an element from a specific position in a list. element() retrieves a single element from a list.
Syntax: element(list, index)
Example:
1 2 3 4 5 6 |
## Open terraform console terraform console ## Get an element from a specific position in a list element([1,2,3,4,5,6,7,8],0) ## returns 1 element([0,1,2,3,4,5],3) ## returns 3 |
If you want to get the index value of an element in a list in terraform, use terraform function index() which finds the element index for a given value in a list.
Syntax: index(list, value)
Example:
1 2 3 |
## Get the index value of an element in a list index([1,2,3,4,5,6,7,8],1) ## returns 0 index([0,1,2,3,4,5],3) ## returns 3 |