How to get some elements from a list in terraform based on their position?

You can use terraform slice() function to get some elements from a list based on their position. slice() extracts some consecutive elements from within a list.

Syntax: slice(list, startindex, endindex)

Example: