https://pulumi.com logo
Title
w

wet-noon-14291

03/19/2021, 11:20 PM
How do I set up a parent/child relation with nested component resources? This is sort of the code I have (simplified):
ResourceB extends pulumi.ComponentResource {
    constructor(name: string, options: pulumi.ComponentResourceOptions) {
        super("....", name, options);
    }
}

ResourceA extends pulumi.ComponentResource {
    constructor(name: string) {
        super("....", name, {});
        new ResourceB(name, { parent: this });
    }
}
With this code I would expect to get the following resource graph:
(stack) -> A -> B
instead I get
(stack) -> A
        \-> B
What do I do wrong? How do I get the first graph?
b

bored-oyster-3147

03/19/2021, 11:22 PM
your component resource should take in
ComponentResourceOptions
which has the parent property on it
w

wet-noon-14291

03/19/2021, 11:24 PM
@bored-oyster-3147, see updated post. I accidently posted to early 🙂
b

bored-oyster-3147

03/19/2021, 11:24 PM
gotcha
so both of them have the stack as a parent?
w

wet-noon-14291

03/19/2021, 11:29 PM
yes
The example is simplified. A should have multiple children and so should B. All the childrens on the same level as B are connected to the stack instead of A.
b

bored-oyster-3147

03/19/2021, 11:33 PM
do all of B's children at least belong to B? And do all of A's children that are not also `ComponentResource`s correctly belong to A?
w

wet-noon-14291

03/19/2021, 11:34 PM
all childre of A are ComponentResources
I can throw in another just to check 🙂
Added
new random.RandomUuid(name+"deleteme", undefined, {parent: this});
in the constructor of A, and that worked as expected. So something wrong with
ComponentResource
?
b

bored-oyster-3147

03/19/2021, 11:42 PM
I'm looking at the SDK code and there is nothing that looks like parents work any differently, so I'm thinking maybe it is just the graphing that is treating ComponentResources different
ComponentResourceOptions
extends
ResourceOptions
and
ComponentResource
extends
Resource
so that options instance is just passed to the base
Resource
as-is which means that parent property should be treated identically
how are you figuring out what the actual parent is? does the state file say the `ResourceB`'s parent is the stack or
ResourceA
?
w

wet-noon-14291

03/20/2021, 12:29 AM
Will check state file tomorrow. I checked the graph in the UI.
l

little-cartoon-10569

03/20/2021, 2:58 AM
Are you passing
parent: this
as the args parameter of ResourceB? It needs to be in the opts parameter.
w

wet-noon-14291

03/20/2021, 9:25 PM
@bored-oyster-3147, checked the stack export now, and ResourceB has the stack as parent and not ResourceA.
@little-cartoon-10569, I call it as in the example in the post. There you see I call I have the parent set when initiating ResourceB from the constructor of ResourceA.
b

bored-oyster-3147

03/20/2021, 9:27 PM
Something weird or something im unaware of going on then. I'd open an issue so pulumi guys get eyes on it
w

wet-noon-14291

03/20/2021, 9:30 PM
I might actually be in to something.
I was calling
super
wrong. The third argument is the args, and that is where I tried to pass in the options. Changing to
super("....", name", undefined, options);
in ResourceB fixed it.
b

bored-oyster-3147

03/20/2021, 9:35 PM
haha damn sorry i didn't notice that. glad you did and that it is working
it's those damn weakly typed languages! shakes fist
w

wet-noon-14291

03/20/2021, 9:37 PM
thanks for rubber ducking though 😆 . I agree on the language part. I did use F# first, but the SDK lends it better for C# or typescript as it is now IMO.
b

bored-oyster-3147

03/20/2021, 9:38 PM
I'm almost exclusively a C# dev, but I would really like to learn F# more. The functional landscape is still a bit foreign to me but I think pulumi would lend itself well to it
w

wet-noon-14291

03/20/2021, 9:40 PM
That's what I think as well, but the SDK is more geared towards C#. I do however have a some pulumi F# in the wild. When you've created your helper functions you can get a pretty sweet DSL. Then there is this project as well which is super interesting: https://github.com/UnoSD/Pulumi.FSharp.Extensions
b

bored-oyster-3147

03/20/2021, 9:41 PM
The TS implementation does have a bit of an easier time with pulumi, mostly because of all the union typing and it relies heavily on function serialization for dynamic providers and I would cringe into oblivion if I saw an implementation attempt that in C#
That is pretty cool though I'll check it out! though I am a bit trepidatious because the resource declarations start to look more like terraform again lol
w

wet-noon-14291

03/21/2021, 9:15 PM
Might be, but they are strongly typed and you should get some help in the IDE if it has F# support.