https://pulumi.com logo
Title
b

bumpy-summer-9075

07/08/2021, 7:41 PM
It's me again about dynamic resources... I'm really struggling to understand how outputs are handled. In one example in the documentation, we have:
export class MyResource extends pulumi.dynamic.Resource {
    public readonly myStringOutput!: pulumi.Output<string>;
    public readonly myNumberOutput!: pulumi.Output<number>;

    constructor(name: string, props: MyResourceInputs, opts?: pulumi.CustomResourceOptions) {
        super(myprovider, name, { myStringOutput: undefined, myNumberOutput: undefined, ...props }, opts);
    }
}
from my own experimentation, it would seem that passing
myStringOutput: undefined
to
super
is how the property
this.myStringOutput
is populated... I'm really weirded out by this, they are not the same variable/reference and there's very little documentation on it. How are they "linked" together?
b

bored-oyster-3147

07/08/2021, 8:37 PM
You are correct that that object expansion is necessary, and the reason for it is undocumented. I have not been able to figure out why or how that functions.
pulumi.dynamic.Resource
immediately passes those props to the
pulumi.CustomResource
constructor which extends and passes them to
pulumi.Resource
. So it doesn't appear to be anywhere in the core NodeJS SDK. Maybe it is something here ? This looks to be the code where your dynamic provider is actually retrieved and invoked during pulumi execution. But if we look at where the create function happens we see: 1. props are retrieved, which is what contains the expansion of undefined output properties 2. provider is retrieved 3. create is invoked with the props that were provided to the resource. Result is received from provider (which isn't doing anything special with those undefined props because it's just an interface that is consumer implemented) 4. the
resultIncludingProvider(...)
function does some object expansion to add the provider property to the result object for some reason? 5. and then we set the RPC response and return. Maybe
structproto.Struct.fromJavascript(....)
is doing something weird cause it is being passed the extended result object? But If I understand what
resultIncludingProvider(...)
is doing than we would've lost those undefined properties after calling that function Can't figure it out 🤷‍♂️
👀 1
b

bumpy-summer-9075

07/08/2021, 9:16 PM
Wow those are so nice pointers, thank you. My understanding is that is it coming from
resp.setProperties(structproto.Struct.fromJavaScript(resultProps));
since
resultProps
contains both the
Hmm I'm not sure anymore
b

bored-oyster-3147

07/08/2021, 9:26 PM
yea honestly the dynamic provider implementation is really weird and I would love to see either a dev blog on how it functions or some more fleshed out documentation on it. And my biggest feature request right now for pulumi is adding dynamic provider support to the dotnet sdk.
b

bumpy-summer-9075

07/08/2021, 9:44 PM
Yikes, yeah better documentation would help a ton. That being said, the "magic" of the prop needing to match the class property is indeed really weird, but I'm sure there's a reason behind it (there's always a reason). I'm surprised this feature is not all that common, I didn't find many examples or projects using them on github.