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

Confusing error message: "Inconsistent conditional result types. The given expressions are object and object, respectively." #30562

Closed
orgads opened this issue Feb 20, 2022 · 3 comments · Fixed by #30920
Assignees
Labels
bug explained a Terraform Core team member has described the root cause of this issue in code v1.1 Issues (primarily bugs) reported against v1.1 releases

Comments

@orgads
Copy link

orgads commented Feb 20, 2022

Terraform Version

Terraform v1.1.6
on linux_amd64
output "test" {
  value = true ? { foo = { bar = 42 } } : { bar = 44 }
}

Debug Output

https://gist.github.com/orgads/3b408edbceccfe3e259daaa880ffe6d0

Expected Behavior

I expect it to work, as both types are objects.

In my case, I needed it as an input to merge.

Actual Behavior

The true and false result expressions must have consistent types. The given expressions are object and object, respectively.

Steps to Reproduce

  1. terraform init
  2. terraform apply

References

@orgads orgads added bug new new issue not yet triaged labels Feb 20, 2022
@kmoe kmoe self-assigned this Feb 22, 2022
@kmoe kmoe added explained a Terraform Core team member has described the root cause of this issue in code v1.1 Issues (primarily bugs) reported against v1.1 releases and removed new new issue not yet triaged labels Feb 25, 2022
@kmoe kmoe changed the title Inconsistent conditional result types. The given expressions are object and object, respectively. Confusing error message: "Inconsistent conditional result types. The given expressions are object and object, respectively." Feb 25, 2022
@kmoe
Copy link
Member

kmoe commented Feb 25, 2022

Thanks for opening this issue. The two expressions in this conditional are both object types, but two objects with attribute types which are collections or structural types (e.g. { bar = 42 }) must have the same attribute types in order for Terraform to consider them convertible.

For example, the following two objects are convertible:
{ foo = { bar = 42 } }
{ foo = { bar = 44 } }

but the following two are not:
{ foo = { bar = 42 } }
{ foo = 41 }

However, the error message "The given expressions are object and object, respectively" is clearly not helpful here. This ticket will be left open until we have improved this error message. Thanks again for bringing this to our attention!

@orgads
Copy link
Author

orgads commented Apr 25, 2022

Thank you!

@github-actions
Copy link

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 May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug explained a Terraform Core team member has described the root cause of this issue in code v1.1 Issues (primarily bugs) reported against v1.1 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants