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

     1  ---
     2  layout: "functions"
     3  page_title: "toset - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-conversion-toset"
     5  description: |-
     6    The toset function converts a value to a set.
     7  ---
     8  
     9  # `toset` 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  `toset` converts its argument to a set value.
    16  
    17  Explicit type conversions are rarely necessary in Terraform because it will
    18  convert types automatically where required. Use the explicit type conversion
    19  functions only to normalize types returned in module outputs.
    20  
    21  Pass a _list_ value to `toset` to convert it to a set, which will remove any
    22  duplicate elements and discard the ordering of the elements.
    23  
    24  ## Examples
    25  
    26  ```
    27  > toset(["a", "b", "c"])
    28  [
    29    "a",
    30    "b",
    31    "c",
    32  ]
    33  ```
    34  
    35  Since Terraform's concept of a set requires all of the elements to be of the
    36  same type, mixed-typed elements will be converted to the most general type:
    37  
    38  ```
    39  > toset(["a", "b", 3])
    40  [
    41    "a",
    42    "b",
    43    "3",
    44  ]
    45  ```
    46  
    47  Set collections are unordered and cannot contain duplicate values, so the
    48  ordering of the argument elements is lost and any duplicate values are
    49  coalesced:
    50  
    51  ```
    52  > toset(["c", "b", "b"])
    53  [
    54    "b",
    55    "c",
    56  ]
    57  ```