mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-01-19 02:01:42 -05:00
This commit adds an `alltrue` function to Terraform configuration. A
reason we might want this function is because it will enable more
powerful custom variable validations. For example:
```hcl
variable "amis" {
type = list(object({
id = string
}))
validation {
condition = (alltrue([
for a in var.amis : length(a.id) > 4 && substr(a.id, 0, 4) == "ami-"
]))
error_message = "The ID of at least one AMI was invalid."
}
}
```
755 B
755 B
layout, page_title, sidebar_current, description
| layout | page_title | sidebar_current | description |
|---|---|---|---|
| functions | alltrue - Functions - Configuration Language | docs-funcs-collection-alltrue | The alltrue function determines whether all elements of a collection are true or "true". If the collection is empty, it returns true. |
alltrue Function
-> Note: This page is about Terraform 0.12 and later. For Terraform 0.11 and earlier, see 0.11 Configuration Language: Interpolation Syntax.
alltrue returns true if all elements in a given collection are true
or "true". It also returns true if the collection is empty.
alltrue(list)
Examples
> alltrue(["true", true])
true
> alltrue([true, false])
false