mirror of https://github.com/hashicorp/terraform
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."
}
}
```
pull/26326/head
parent
7222bad59c
commit
6ed47c7241
@ -0,0 +1,30 @@
|
||||
---
|
||||
layout: functions
|
||||
page_title: alltrue - Functions - Configuration Language
|
||||
sidebar_current: docs-funcs-collection-alltrue
|
||||
description: |-
|
||||
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](../../configuration-0-11/interpolation.html).
|
||||
|
||||
`alltrue` returns `true` if all elements in a given collection are `true`
|
||||
or `"true"`. It also returns `true` if the collection is empty.
|
||||
|
||||
```hcl
|
||||
alltrue(list)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```command
|
||||
> alltrue(["true", true])
|
||||
true
|
||||
> alltrue([true, false])
|
||||
false
|
||||
```
|
||||
Loading…
Reference in new issue