github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/language/functions/toset.html.md (about) 1 --- 2 layout: "language" 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 `toset` converts its argument to a set value. 12 13 Explicit type conversions are rarely necessary in Terraform because it will 14 convert types automatically where required. Use the explicit type conversion 15 functions only to normalize types returned in module outputs. 16 17 Pass a _list_ value to `toset` to convert it to a set, which will remove any 18 duplicate elements and discard the ordering of the elements. 19 20 ## Examples 21 22 ``` 23 > toset(["a", "b", "c"]) 24 [ 25 "a", 26 "b", 27 "c", 28 ] 29 ``` 30 31 Since Terraform's concept of a set requires all of the elements to be of the 32 same type, mixed-typed elements will be converted to the most general type: 33 34 ``` 35 > toset(["a", "b", 3]) 36 [ 37 "a", 38 "b", 39 "3", 40 ] 41 ``` 42 43 Set collections are unordered and cannot contain duplicate values, so the 44 ordering of the argument elements is lost and any duplicate values are 45 coalesced: 46 47 ``` 48 > toset(["c", "b", "b"]) 49 [ 50 "b", 51 "c", 52 ] 53 ```