sparse-intern-71089
03/09/2023, 9:09 AMicy-controller-6092
03/09/2023, 9:14 AMWhy would you make a component resource instead of just a “simple” logical grouping that you can call and use like a generic library full of classes and functions? A component resource shows up in the Pulumi ecosystem just like any other resource. That means it has a trackable state, appears in diffs, and has a name field you can reference that refers to the entire grouping.However, all three things don’t seem all that meaningful: 1. trackable state - in this thread on github, a pulumi contributor says “but state for component resources is basically meaningless anyway” 2. appears in diffs - if state on a component resource is meaningless, then so is any diff 3. a name field you can use to reference the entire grouping - you can also do this if you have a root component in the hierarchy you create inside a function via
parent
icy-controller-6092
03/09/2023, 9:15 AMbrave-planet-10645
03/09/2023, 12:42 PMlittle-cartoon-10569
03/09/2023, 8:09 PMicy-controller-6092
03/09/2023, 9:51 PMprovider
opt to some of the child resources
now if only there were also a way to avoid having to put { parent: this }
on every component in the constructorlittle-cartoon-10569
03/09/2023, 9:53 PMicy-controller-6092
03/10/2023, 9:50 PM{ parent: this }
in the constructor 🙁icy-controller-6092
03/10/2023, 10:46 PMthis.addResource('role', aws.iam.Role, { … })
private addResource<T extends pulumi.Resource>(
name: string,
Resource: T,
args: ConstructorParameters<T>[1]
) {
return new Resource(`${this.name}-${name}`, args, { parent: this })
}
icy-controller-6092
03/10/2023, 10:51 PMResource
is very loosely typed, could probably fix it if I new how to use infer
correctly
private addResource<T extends new (...args: any) => any>(
name: string,
Resource: T,
args: ConstructorParameters<T>[1]
) {
return new Resource(`${this.name}-${name}`, args, { parent: this })
}
little-cartoon-10569
03/11/2023, 9:15 AMthis
won't always be the parent.
We just have it as a coding convention that's on our code review checklist for Pulumi code.No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by