-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider::assert::null() not behaving as expected #71
Comments
Some clarification after investigating further. It only seems like an issue when doing cross-object references in variable validation. The following fails like before: variable "cidr_block" {
default = null
description = "CIDR block for the VPC."
type = string
validation {
condition = anytrue([
provider::assert::null(var.cidr_block),
provider::assert::cidr(var.cidr_block)
])
error_message = "CIDR block must be a valid CIDR range."
}
validation {
condition = anytrue([
alltrue([
provider::assert::not_null(var.cidr_block),
provider::assert::null(var.ipv4_ipam_pool_id)
]),
alltrue([
provider::assert::null(var.cidr_block),
provider::assert::not_null(var.ipv4_ipam_pool_id)
])
]) # XOR
error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
}
} However, this small change fixes it: variable "cidr_block" {
default = null
description = "CIDR block for the VPC."
type = string
validation {
condition = anytrue([
provider::assert::null(var.cidr_block),
provider::assert::cidr(var.cidr_block)
])
error_message = "CIDR block must be a valid CIDR range."
}
validation {
condition = anytrue([
alltrue([
provider::assert::not_null(var.cidr_block),
var.ipv4_ipam_pool_id == null #.................. this is the change
]),
alltrue([
provider::assert::null(var.cidr_block),
provider::assert::not_null(var.ipv4_ipam_pool_id)
])
]) # XOR
error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
}
} So, my thought was that the cross-object reference is receiving the "zero value" from the nulled variable. To validate this, I ran the following which failed, as I was thinking it would, verifying this: variable "cidr_block" {
default = null
description = "CIDR block for the VPC."
type = string
validation {
condition = anytrue([
provider::assert::null(var.cidr_block),
provider::assert::cidr(var.cidr_block)
])
error_message = "CIDR block must be a valid CIDR range."
}
validation {
condition = alltrue([
anytrue([
alltrue([
provider::assert::not_null(var.cidr_block),
var.ipv4_ipam_pool_id == null
]),
alltrue([
provider::assert::null(var.cidr_block),
provider::assert::not_null(var.ipv4_ipam_pool_id)
])
]),
!alltrue([
provider::assert::not_null(var.cidr_block),
provider::assert::not_null(var.ipv4_ipam_pool_id)
])
]) # XOR
error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
}
} So, it appears to be more of a problem with cross-object reference behavior than the provider. Although, while investigating the code... I am curious why |
Hi @dustindortch, Thank you for reporting this issue. In v0.15.0, we merged a fix to evaluate the underlying value as It would be greatly appreciated if you could test this out and let us know if it resolves your issue. I’ve also added a test to the |
@bschaatsbergen taking a look now, thanks! |
@bschaatsbergen it works! Fantastic! Thank you! |
I am doing some compound validation and I will use
alltrue()
,anytrue()
, orsum()
in my validation for AND, OR, and XOR operations, respectively.The following fails validation:
Results:
The following validation works as expected:
Are these doing some sort of blocking failures? This seems bad if the context would be either inside a
check
block, which should be non-blocking, or inside ofterraform test
with an expected failure. It really limits the application.The text was updated successfully, but these errors were encountered: