Skip to content
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

Variable Validation should use lazy evaluation #24998

Closed
matteomazza91 opened this issue May 20, 2020 · 2 comments
Closed

Variable Validation should use lazy evaluation #24998

matteomazza91 opened this issue May 20, 2020 · 2 comments
Labels
custom-conditions Feedback on variable validation, preconditions. postconditions, checks, and test assertions

Comments

@matteomazza91
Copy link

Terraform Version

0.12.24

Terraform Configuration Files

variable "my_variable_name" {
  type = object({
    a = string
    b = string
  })
  validation {
    condition     = var.my_variable_name == null || (var.my_variable_name.a != null && var.my_variable_name.b != null)
    error_message = "Something."
  }
}

Debug Output

Error: Attempt to get attribute from null value

  on [...]/variables.tf line 96, in variable "my_variable_name":
  96:     condition     = var.my_variable_name == null || (var.my_variable_name.a != null && var.my_variable_name.b != null)
    |----------------
    | var.my_variable_name is null

This value is null, so it does not have any attributes.

  on [...]/variables.tf line 96, in variable "my_variable_name":
  96:     condition     = var.my_variable_name == null || (var.my_variable_name.a != null && var.my_variable_name.b != null)
    |----------------
    | var.my_variable_name is null

This value is null, so it does not have any attributes.

Expected Behavior

if var.my_variable_name is null, the condition for variable-validation should evaluate to true

Actual Behavior

error returned because the right part of the validation expression is evaluated. It fails evaluating both var.my_variable_name.a and var.my_variable_name.b because var.my_variable_name is null

@pkolyvas pkolyvas added the custom-conditions Feedback on variable validation, preconditions. postconditions, checks, and test assertions label May 29, 2020
@jbardin
Copy link
Member

jbardin commented Mar 31, 2021

Hello @matteomazza91,

Thanks for filing the issue. This isn't specific to variable validation, conditional operators not short-circuiting evaluation is a known issue we're tracking in #24128.

Closing as a duplicate.

@jbardin jbardin closed this as completed Mar 31, 2021
@ghost
Copy link

ghost commented May 1, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
custom-conditions Feedback on variable validation, preconditions. postconditions, checks, and test assertions
Projects
None yet
Development

No branches or pull requests

3 participants