mirror of https://github.com/pulumi/pulumi.git
66a372a7d7
12749: [pcl/nodejs] Support range expressions that are of type output r=Zaid-Ajaj a=Zaid-Ajaj # Description This PR implements nodejs program-gen support for `range` expressions that are of type `Output<T>` where `T` is a collection that should be iterated inside an `apply` call. <details> <summary>Example PCL</summary> ```terraform resource "root" "range:index:Root" {} // creating resources by iterating a property of type array(string) of another resource resource "fromListOfStrings" "range:index:Example" { options { range = root.arrayOfString } someString = range.value } // creating resources by iterating a property of type map(string) of another resource resource "fromMapOfStrings" "range:index:Example" { options { range = root.mapOfString } someString = "${range.key} ${range.value}" } // computed range list expression to create instances of range:index:Example resource resource "fromComputedListOfStrings" "range:index:Example" { options { range = [ root.mapOfString["hello"], root.mapOfString["world"] ] } someString = "${range.key} ${range.value}" } // computed range for expression to create instances of range:index:Example resource resource "fromComputedForExpression" "range:index:Example" { options { range = [for value in root.arrayOfString : root.mapOfString[value]] } someString = "${range.key} ${range.value}" } ``` </details> <details> <summary>Generated TypeScript</summary> ```typescript import * as pulumi from "`@pulumi/pulumi";` import * as range from "`@pulumi/range";` const root = new range.Root("root", {}); // creating resources by iterating a property of type array(string) of another resource const fromListOfStrings: range.Example[] = []; root.arrayOfString.apply(rangeBody => { for (const range of rangeBody.map((v, k) => ({key: k, value: v}))) { fromListOfStrings.push(new range.Example(`fromListOfStrings-${range.key}`, {someString: range.value})); } }); // creating resources by iterating a property of type map(string) of another resource const fromMapOfStrings: range.Example[] = []; root.mapOfString.apply(rangeBody => { for (const range of Object.entries(rangeBody).map(([k, v]) => ({key: k, value: v}))) { fromMapOfStrings.push(new range.Example(`fromMapOfStrings-${range.key}`, {someString: `${range.key} ${range.value}`})); } }); // computed range list expression to create instances of range:index:Example resource const fromComputedListOfStrings: range.Example[] = []; pulumi.all([ root.mapOfString.apply(mapOfString => mapOfString?.hello), root.mapOfString.apply(mapOfString => mapOfString?.world), ]).apply(rangeBody => { for (const range of rangeBody.map((v, k) => ({key: k, value: v}))) { fromComputedListOfStrings.push(new range.Example(`fromComputedListOfStrings-${range.key}`, {someString: `${range.key} ${range.value}`})); } }); // computed range for expression to create instances of range:index:Example resource const fromComputedForExpression: range.Example[] = []; pulumi.all([root.arrayOfString, root.mapOfString]).apply(([arrayOfString, mapOfString]) => { for (const range of arrayOfString.map(value => (mapOfString[value])).map((v, k) => ({key: k, value: v}))) { fromComputedForExpression.push(new range.Example(`fromComputedForExpression-${range.key}`, {someString: `${range.key} ${range.value}`})); } }); ``` </details> ## Checklist <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. --> Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com> |
||
---|---|---|
.. | ||
20230426--programgen-nodejs--support-range-expressions-that-are-of-type-output.yaml |