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

Conditional expression not working as expected when using OR logic #32641

Closed
daniel-butler-irl opened this issue Feb 8, 2023 · 2 comments
Closed
Labels
bug duplicate issue closed because another issue already tracks this problem

Comments

@daniel-butler-irl
Copy link

Terraform Version

Terraform v1.3.7                                                                                                                
on darwin_amd64

Terraform Configuration Files

# Example distilled to its simplest form
variable "test" {
  type = list(string)
  default = null
}

locals {
  myvar = var.test == null || length(var.test) == 0 ? ["no value"] : var.test
}

Debug Output

❯ terraform plan
╷
│ Error: Invalid function argument
│ 
│   on main.tf line 8, in locals:
│    8:   myvar = var.test == null || length(var.test) == 0 ? ["no value"] : var.test
│     ├────────────────
│     │ while calling length(value)
│     │ var.test is null
│ 
│ Invalid value for "value" parameter: argument must not be null.

Expected Behavior

After evaluating var.test == null is true the or is satisfied so myvar should be set to ["no value"]

Actual Behavior

Tries to evaluate length on a null object unnecessarily.

Steps to Reproduce

  1. terraform plan

Additional Context

After evaluating the first condition the OR is satisfied, no need to evaluate the other conditions. There are workarounds but this format should work.

References

No response

@daniel-butler-irl daniel-butler-irl added bug new new issue not yet triaged labels Feb 8, 2023
@jbardin
Copy link
Member

jbardin commented Feb 8, 2023

Duplicate of #24128

@jbardin jbardin marked this as a duplicate of #24128 Feb 8, 2023
@jbardin jbardin closed this as completed Feb 8, 2023
@crw crw added duplicate issue closed because another issue already tracks this problem and removed new new issue not yet triaged labels Feb 8, 2023
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug duplicate issue closed because another issue already tracks this problem
Projects
None yet
Development

No branches or pull requests

3 participants