github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/slice.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "slice - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-collection-slice"
     5  description: |-
     6    The slice function extracts some consecutive elements from within a list.
     7  ---
     8  
     9  # `slice` 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  `slice` extracts some consecutive elements from within a list.
    16  
    17  ```hcl
    18  slice(list, startindex, endindex)
    19  ```
    20  
    21  `startindex` is inclusive, while `endindex` is exclusive. This function returns
    22  an error if either index is outside the bounds of valid indices for the given
    23  list.
    24  
    25  ## Examples
    26  
    27  ```
    28  > slice(["a", "b", "c", "d"], 1, 3)
    29  [
    30    "b",
    31    "c",
    32  ]
    33  ```
    34  
    35  ## Related Functions
    36  
    37  * [`substr`](./substr.html) performs a similar function for characters in a
    38    string, although it uses a length instead of an end index.