Type Constraints - Set

Learn how to use the Terraform type constraints Set.

We'll cover the following...

Set

A set is almost the same as a list. The key difference is that a set only contains unique values.

Press + to interact
variable "my_set" {
type = set(number)
default = [7, 2, 2]
}
variable "my_list" {
type = list(string)
default = ["foo", "bar", "foo"]
}
output "set" {
value = var.my_set
}
output "list" {
value = var.my_list
}
output "list_as_set" {
value = toset(var.my_list)
}

In the above example, we define a variable called my_set and initialize it to the set [7, 2, 2]. As stated above, a set only contains unique values, so when we run this ...