pulumi/pkg/codegen/pcl
Zaid Ajaj 0d458a47df
[program-gen] Fix PCL bind error "cannot iterate over a value of type number" (#17569)
### 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.
2024-10-17 20:55:38 +00:00
..
README.md Document code generation concepts (#17162) 2024-09-05 13:12:59 +00:00
binder.go Clean up uses of .Error() (#14965) 2023-12-20 15:54:06 +00:00
binder_component.go [pcl] Detect and error on binding component nodes that self-reference their source (#17538) 2024-10-11 12:45:16 +00:00
binder_nodes.go Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00
binder_resource.go [program-gen] Fix PCL bind error "cannot iterate over a value of type number" (#17569) 2024-10-17 20:55:38 +00:00
binder_resource_test.go Support loading parameterized schemas in the schema loader (#17108) 2024-08-30 14:25:29 +00:00
binder_schema.go [docs] Fix generating constructor examples for resources that have numeric enums as input (#16223) 2024-05-30 22:43:12 +00:00
binder_schema_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
binder_test.go [program-gen] Fix PCL bind error "cannot iterate over a value of type number" (#17569) 2024-10-17 20:55:38 +00:00
component.go lint 2023-07-27 16:32:06 +02:00
config.go Implement description as comments or docstring for config variables in program-gen 2023-03-21 15:01:16 +01:00
diagnostics.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
functions.go Add an `organization` intrinsic to PCL (#16948) 2024-08-19 03:58:19 +00:00
functions_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
intrinsics.go all: Assert => Assertf 2023-03-03 14:37:43 -08:00
invoke.go Update golangci-lint (#14624) 2023-11-21 15:16:13 +00:00
local.go Do not panic when the type of PCL local variable isn't known 2023-04-13 20:05:16 +02:00
output.go codegen: preserve externally visible names of a resources and outputs (#9464) 2022-04-25 15:07:25 -07:00
program.go Use slice.Prealloc instead of make([]T, 0, ...) 2023-06-29 11:27:50 +01:00
resource.go Add support for `DeletedWith` to `pulumi convert` (#12011) 2024-07-19 14:17:45 +00:00
rewrite_apply.go Vendor the inflector library (#16421) 2024-06-20 09:04:33 +00:00
rewrite_apply_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
rewrite_convert.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
rewrite_convert_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
rewrite_properties.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
type.go [codegen] simplify opaque types to string newtype (#9770) 2022-06-13 11:13:03 -07:00
utilities.go lint 2023-07-28 20:47:36 +02:00
utilities_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00

README.md

(pcl)=

Pulumi Configuration Language (PCL)

Pulumi Configuration Language (PCL) is an internal representation of Pulumi programs which supports all core concepts of the Pulumi programming model in a minimal form. Although not exposed directly to users today, this intermediate representation is used to support a variety of program conversion tasks, from and to various supported Pulumi languages.