https://pulumi.com logo
Title
l

limited-rainbow-51650

10/27/2021, 8:09 PM
As long as one can create resources and pass outputs between them, my coding goes fine and smooth. But for the n-th time, I'm struggling when I have to mix in a get function. Context: I have a regular Javascript function creating, first calling a get function and based on the output, creating 2 resources and returning me a
Promise
which I used correctly in my code. So far so good. I'm now trying to convert that function to a
pulumi.ComponentResource
subclass, where I have the get function and the resource creation as well. But in that move, it seems I broke the setup for correct async processing. When I try to refer to the outputs of my
ComponentResource
, they still seem to be
undefined
. Each output in my component is an output from each of the 2 child resources. Does anyone have an example of a
ComponentResource
which mixes a get function, resource creation based on the fetched info and exposing outputs on the component class?
l

little-cartoon-10569

10/27/2021, 8:20 PM
Is it one of the get functions that returns a Promise, rather than an Output?
I have a fair few resources like that. Here's a snippet from the constructor of one.
b

billowy-army-68599

10/27/2021, 8:24 PM
l

little-cartoon-10569

10/27/2021, 8:25 PM
The important bit imo is that Promises returned from get functions like getAmi have to be wrapped in
pulumi.output()
l

limited-rainbow-51650

10/27/2021, 8:41 PM
@billowy-army-68599 that issue is indeed my mental tormentation. ๐Ÿ™‚
@little-cartoon-10569 my code looks very similar to yours regarding, except for the place where you use
pulumi.output(...)
wrapping.
Let me try it around the get function.
b

billowy-army-68599

10/27/2021, 8:46 PM
@limited-rainbow-51650 i believe your experience is going to get much better here pretty soon ๐Ÿ˜„
l

limited-rainbow-51650

10/27/2021, 8:47 PM
@billowy-army-68599 you mean by applying the suggestion from @little-cartoon-10569, or by you and your colleagues fixing that issue? ๐Ÿ˜„
b

billowy-army-68599

10/27/2021, 8:48 PM
by making the experience better, accepting outputs in functions
๐ŸŽ‰ 1
but any time tenwit is involved your life gets better too ๐Ÿ˜„
๐Ÿ’ฏ 1
๐Ÿ˜Š 1
@limited-rainbow-51650 - @enough-garden-22763 pointed me to this: https://github.com/pulumi/examples/pull/1096/files take a look at the experience and let us know what you think
๐Ÿš€ 1
๐Ÿธ 1
๐ŸŽ‰ 1
e

enough-garden-22763

10/27/2021, 9:00 PM
The functions now have $fnOutput forms that return an Output, and accept Input/Output in arguments; these forms behave similarly to what you would do by mechanically wrapping promise-returning functions with an apply block. This should be available in TypeScript already, we are just waiting on languages like C# to land support before making an official blog post about it.
l

limited-rainbow-51650

10/27/2021, 9:01 PM
@enough-garden-22763 which minimal version of Pulumi has this for NodeJS?
e

enough-garden-22763

10/27/2021, 9:02 PM
The relevant version here is version of providers.
๐Ÿ‘๐Ÿผ 1
E.g. https://github.com/pulumi/pulumi-aws/blob/v4.25.0/CHANGELOG.md v4.25.0 definitely has it, itโ€™s not obvious which older version had it, one sec
So sounds like weโ€™re looking at providers built against 3.15.0 (2021-10-14) or higher of pulumi/pulumi; I canโ€™t seem to easily correlate this through pulumi-aws versions, apologies.
l

limited-rainbow-51650

10/27/2021, 9:06 PM
In my case, I will have to search for versions of the GCP (classic) and Kubernetes providers to have this.
With Kubernetes I donโ€™t seem to find any functions in https://www.pulumi.com/registry/packages/kubernetes/api-docs/ so it does not seem it would be affected; sorry this is the provider Iโ€™m a bit less familiar with, so if you give me an example piece of code you are thinking of updating that can help me find it quickly.
l

limited-rainbow-51650

10/27/2021, 9:25 PM
@enough-garden-22763 with all the help I got so far, I was able to fix it. I will definitely start to use the new function Output functionality ASAP. It simplifies the coding a lot!
โค๏ธ 1