Files
opentf/website/docs/configuration/functions/alltrue.html.md
Arthur Burkart 6ed47c7241 lang/funcs: Add "alltrue" function (#25656)
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."
  }
}
```
2020-09-22 09:06:42 -04:00

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