mirror of https://github.com/pulumi/pulumi.git
0d458a47df
### Description
Often when converting terraform modules such as tf VPC module, the range
expression of resources is a conditional expression of the form `if
should_create_resource ? N : 0`.
These expressions resolve their type to one of `int`, `bool`,
`Output[int]` or `Output[bool]`. Any other type we assume we are dealing
with a collection that we are trying to iterate over. However if the
conditional expression resolves to `optional(int)` then we think it is a
collection, try to get it's key-value pair types and error with "cannot
iterate over a value of type number"
This PR fixes this problem by unwrapping `int` from `optional(int)` when
encountered in these range expressions.
I was able to isolate a subset of the converted PCL from terraform VPC
module where this problem occurs and created a unit test from it.
Interesting note is that this only occurs in _non-strict_ mode 🤔 in
strict mode, the expression type from `range` is not optional. I've not
been able to find out why that is the case yet.
|
||
---|---|---|
.. | ||
20240922--engine--fix-token-expired-errors-due-to-network-issues.yaml | ||
20240924--programgen-python--fix-preserving-map-keys-in-python-programgen.yaml | ||
20240930--sdk-go--enable-better-error-messsages-to-be-returned-from-provider-construct-failures.yaml | ||
20240930--sdk-python--enable-better-error-messsages-to-be-returned-from-provider-construct-failures.yaml | ||
20241003--cli--allow-memory-profile-to-be-written-occasionally-in-case-of-crash.yaml | ||
20241008--pkg--dont-publish-test-code-in-pkg-codegen.yaml | ||
20241008--sdk-python--support-python-3-13.yaml | ||
20241010--programgen--detect-and-error-on-binding-component-nodes-in-pcl-programs-that-self-reference-their-source.yaml | ||
20241010--yaml--update-yaml-to-1-11-1.yaml | ||
20241011--sdk-go--improve-error-message-when-credentials-file-invalid.yaml | ||
20241015--yaml--allow-pulumi-package-add-for-yaml-projects.yaml | ||
20241017--programgen--fix-pcl-bind-error-cannot-iterate-over-a-value-of-type-number-when-conditionals-are-used-in-range-expressions.yaml |