broad-helmet-79436
12/21/2021, 11:30 AMparent
when I make them fields/properties of a ComponentResource class? E.g. here, I would really like to not have to explicitly specify `{ parent: this }`:
class A extends pulumi.ComponentResource {
readonly id: random.RandomId;
constructor(name: string, args: {}, opts: pulumi.ComponentResourceOptions) {
super('martin:A', name, {}, opts);
this.id = new random.RandomId(
name,
{ byteLength: 42 },
{ parent: this }
);
}
}
I think that setting a Pulumi resource as a field in a class that extends pulumi.ComponentResource like I do in the example (and in pretty much all of my code) is a pretty clear expression of intent for the resource to be a child of the component resource class.
I do it this way so I can set providers: [k8sProvider, gcpProvider]
and protect: true
on a single parent resource instead of passing the correct provider to every single resource. And the logical grouping in the diff output is nice too, but not enough that I’d bother to set a field on Every Single Resource.
This is a source of continuous frustration as I keep forgetting about it when I add new resources to classes, and don’t always notice even when I run pulumi up
given that it’s completely valid to define a resource without a parent 😅green-school-95910
12/21/2021, 4:14 PMAutoParentComponentResource
and use that as your base class.little-cartoon-10569
12/21/2021, 7:46 PMconst child = new Resource(name, args, { ...opts, parent: parent})
. The splat / spread operator is great here. I don't recommend using parent: this
unilaterally. Lots of child resources in my stacks are children of children, so this
would be wrong.broad-helmet-79436
12/22/2021, 2:49 PM