github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/toset.mdx (about)

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