-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Boolean operators should be capable of converting unknown values to known #31078
Description
Boolean operators && and || should be capable of converting unknown values to known values based on standard boolean logic.
&& |
true |
false |
unknown |
|---|---|---|---|
true |
true |
false |
unknown |
false |
false |
false |
false |
unknown |
unknown |
false |
unknown |
|| |
true |
false |
unknown |
|---|---|---|---|
true |
true |
true |
true |
false |
true |
false |
unknown |
unknown |
true |
unknown |
unknown |
Terraform Version
1.1.7
Terraform Configuration Files
This is obviously contrived to show the issue, but in practice this sort of thing allows certain configurations to tolerate certain unknowns. For example, a configuration could require either a list of AWS Availability Zones (AZs) or the number of zones to use, with the final list of AZs being either the configured list or the list from a data source, and the final count being either the provided count or the size of the configured list of AZs. Currently this has to be carefully managed with the tertiary operator ? : but it should be able to be managed with straightforward boolean arithmetic.
variable "known" {
type = bool
default = false
}
resource "null_resource" "unknown" {
}
locals {
computed = var.known && (length(null_resource.unknown.id) == 3)
# The following statement avoid the problem:
# computed = var.known ? length(null_resource.unknown.id) == 3 : false
}
resource "null_resource" "count" {
count = local.computed ? 1 : 0
}
Expected Behavior
count should be known at plan time.
Actual Behavior
Error: Invalid count argument
Steps to Reproduce
terraform initterraform apply