Skip to content

Instantly share code, notes, and snippets.

@mattfysh
Last active May 19, 2023 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattfysh/81a761119c84b7d026bf1ca1a9c2220c to your computer and use it in GitHub Desktop.
Save mattfysh/81a761119c84b7d026bf1ca1a9c2220c to your computer and use it in GitHub Desktop.
Pulumi auto-hierarchy
export abstract class ProjectResource extends pulumi.ComponentResource {
protected abstract name: string
protected addResource<RT, ResourceArgs>(
name: string,
Resource: new (
name: string,
args: ResourceArgs,
opts: pulumi.CustomResourceOptions
) => RT,
args: ResourceArgs,
opts: pulumi.CustomResourceOptions = {}
) {
return new Resource(`${this.name}-${name}`, args, { ...opts, parent: this })
}
}
export abstract class ProjectResource extends pulumi.ComponentResource {
protected abstract name: string
protected addResource<T, Args>(
name: string,
Resource: new (
name: string,
props: Args,
opts?: pulumi.CustomResourceOptions
) => T,
props: Args,
opts?: pulumi.CustomResourceOptions
) {
return new Resource(`${this.name}-${name}`, props, {
...opts,
parent: this,
})
}
protected addComponentResource<T, Args>(
name: string,
Resource: new (
name: string,
args: Args,
opts?: pulumi.ComponentResourceOptions
) => T,
args: Args,
opts?: pulumi.ComponentResourceOptions
) {
return new Resource(`${this.name}-${name}`, args, { ...opts, parent: this })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment