From 22f64cbbcf8a60ff8a75c59d676bfb9ef252e201 Mon Sep 17 00:00:00 2001 From: hedaya-khalif <171175605+hedaya-khalif@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:15:50 -0400 Subject: [PATCH] Fix #32601 Update Set data type description --- website/docs/language/expressions/types.mdx | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/website/docs/language/expressions/types.mdx b/website/docs/language/expressions/types.mdx index 244f345e83..96b5e5583a 100644 --- a/website/docs/language/expressions/types.mdx +++ b/website/docs/language/expressions/types.mdx @@ -79,6 +79,35 @@ comma-separated sequence of values, like `["a", 15, true]`. List literals can be split into multiple lines for readability, but always require a comma between values. A comma after the final value is allowed, but not required. Values in a list can be arbitrary expressions. +### Sets + +Accessing elements of a set directly by index is not supported because sets are unordered collections. However, you can convert a set to a list to access elements by index. + +Example: Accessing Elements of a Set + +1. Define a Set: +```hcl +variable "example_set" { +type = set(string) +default = ["foo", "bar"] +} +``` +3. Convert Set to List: +```hcl +locals { + example_list = tolist(var.example_set) +} +``` + +5. Access Elements by Index: +```hcl +output "first_element" { + value = local.example_list[0] +} +output "second_element" { + value = local.example_list[1] +} +``` ### Maps/Objects