Type constraints - List

Learn how to use the Terraform type constraints List.

List

A list is a type of a list. You can have a list of strings like ["foo", "bar"] or a list of numbers [2, 4, 7]. The type means that every element in the list will be of that type.

Project example

Consider the following example:

Press + to interact
variable "a" {
type = list(string)
default = ["foo", "bar", "baz"]
}
output "a" {
value = var.a
}
output "b" {
value = element(var.a, 1)
}
output "c" {
value = length(var.a)
}

In the above code, we define a list ...

Access this course and 1400+ top-rated courses and projects.