github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/slice.mdx (about) 1 --- 2 page_title: slice - Functions - Configuration Language 3 description: The slice function extracts some consecutive elements from within a list. 4 --- 5 6 # `slice` Function 7 8 `slice` extracts some consecutive elements from within a list. 9 10 ```hcl 11 slice(list, startindex, endindex) 12 ``` 13 14 `startindex` is inclusive, while `endindex` is exclusive. This function returns 15 an error if either index is outside the bounds of valid indices for the given 16 list. 17 18 ## Examples 19 20 ``` 21 > slice(["a", "b", "c", "d"], 1, 3) 22 [ 23 "b", 24 "c", 25 ] 26 ``` 27 28 ## Related Functions 29 30 * [`substr`](/language/functions/substr) performs a similar function for characters in a 31 string, although it uses a length instead of an end index.