-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 operator cannot be used with list values #18259
Comments
This is still a problem with 0.11.7. So the following complicated interpolation is used:
Instead of
Which the latter is far more readable. |
@iyesin You might be able to get around that by doing a |
Hi all! Sorry for the slow response here. This issue is covering the same idea as #12453, which is now closed because the solution is merged in master ready for the forthcoming v0.12.0 release. You can see over there how I verified it against the v0.12.0-alpha1 prerelease build, along with a caveat caused by another related issue that's yet to be resolved. That caveat unfortunately applies to this example too, but in a different way: since one of the "legs" of the conditional here was a splat expression, the way to work around it for now would be as follows: value = "${aws_subnet.private.count > 0 ? list(aws_subnet.private.*.id...) : list()}" That new Since there's now a fix merged, I'm going to close this out. Thanks for opening this issue, and sorry again that we didn't respond sooner. |
For those that'll still hit this till v0.12 is out, here's a workaround: asg_vpc_zone_identifier = "${split(",", var.env == "production" ? join(",", local.asg_vpc_public_zone_identifier) : join(",", local.asg_vpc_private_zone_identifier))}" Both of the local vars are lists. The It works around the limitation of not being able to use lists with the conditional operator by first joining the lists and eventually passing the result as a list, as originally intended. |
ty for the work around |
It looks like Terraform 0.12 is close, but if you are still on 0.11 there was a workaround highlighted here. It is a little more verbose, but it allows you to actually get lists of more complex types beyond strings out of it. (I used this technique for beanstalk settings to consolidate a bunch of beanstalk apps into one module).
It is significantly more verbose, but a little more flexible since it works with non-string items. |
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. |
Terraform Version
Terraform Configuration Files
Crash Output
Expected Behavior
Actual Behavior
See crash output
Additional Context
This limitation is even not documented.
The text was updated successfully, but these errors were encountered: