steep-secretary-65224
09/30/2024, 2:03 PMregisterOutputs({bucketName: ....}) instead of just declaring and setting this.bucketNamesteep-secretary-65224
09/30/2024, 2:06 PMsteep-secretary-65224
09/30/2024, 2:09 PMregisterOutput as opposed to all of the various ways different languages can expose properties/getters/etcfuture-hairdresser-70637
09/30/2024, 3:21 PMRegisterOutputs signals that the ComponentResource is done creating child resources and is mainly for quicker UI updates. It will not affect the dep graph.
Specifically for TS, see:
https://github.com/pulumi/pulumi/blob/510111fe67666834b7e7ed43242ac60a3eaa524e/sdk/nodejs/resource.ts#L1280
and
https://github.com/pulumi/pulumi/blob/510111fe67666834b7e7ed43242ac60a3eaa524e/sdk/nodejs/runtime/resource.ts#L1131steep-secretary-65224
09/30/2024, 3:31 PMsteep-secretary-65224
09/30/2024, 3:32 PMinitialize over putting all of the logic in the constructor?steep-secretary-65224
09/30/2024, 3:32 PMregisterOutputs is a noopsteep-secretary-65224
09/30/2024, 3:35 PMsuper calls initializeAndRegisterOutputs before it returns to the child constructor. and those don't do anything useful unless you have a custom initialize method (which i don't really see any good examples of/reason to use)future-hairdresser-70637
09/30/2024, 3:42 PMis there any reason to useI would say no, asover putting all of the logic in the constructor?initialize
ComponentResource is "just" a container for other resources; more of an organizational/reuse thing than an actual Resource. I want to say I've seen an example or two that overrode initialize but I can't think of where/whysteep-secretary-65224
09/30/2024, 4:22 PMResourcesteep-secretary-65224
09/30/2024, 4:23 PMregisterOutputsfuture-hairdresser-70637
09/30/2024, 4:37 PMThe call tothere's no absolute guarantee that this will stay unenforcedalso tells Pulumi that the resource is done registering children and should be considered fully constructed, so—although it’s not enforced—the best practice is to call it in all components even if no outputs need to be registered.registerOutputs
future-hairdresser-70637
09/30/2024, 4:37 PMsteep-secretary-65224
09/30/2024, 4:40 PMclass Foo extends ComponentResource {
constructor(......) {
super(....)
// registerOutputs was called by super
new FooResource(....)
// but we're not done creating resources
}
}steep-secretary-65224
10/01/2024, 1:08 AMregisterOutputs does that's somewhat useful is showing resource outputs on the resource page on pulumi cloudsteep-secretary-65224
10/01/2024, 1:10 AMinterface ExampleOutputs {
hostname: Output<string>
}
export class ExampleResource extends ComponentResource<ExampleOutputs> {
protected initialize(args: ExampleArgs): Promise<ExampleOutputs> {
const hostname = args.wildcard ? '*' : args.hostname
const retval = {
hostname,
}
this.registerOutputs(retval)
return Promise.resolve(output(retval))
}
...
}future-hairdresser-70637
10/01/2024, 1:38 AMregisterOutputs?steep-secretary-65224
10/01/2024, 1:39 AMsuper callfuture-hairdresser-70637
10/01/2024, 1:40 AMargs -> output retval ? that is, it's expected the ComponentResource will do "stuff" such as have resources with their parent == thisfuture-hairdresser-70637
10/01/2024, 1:41 AMregisterOutputs https://github.com/pulumi/pulumi/issues/2653steep-secretary-65224
10/01/2024, 1:42 AMfuture-hairdresser-70637
10/01/2024, 1:42 AMfuture-hairdresser-70637
10/01/2024, 1:43 AM[Output] property attribute which registerOutputs looks forsteep-secretary-65224
10/01/2024, 1:43 AMaws.route53.getZone), etcsteep-secretary-65224
10/01/2024, 1:44 AMsteep-secretary-65224
10/01/2024, 1:45 AMthis.registerOutputs(await this.initialize(args)future-hairdresser-70637
10/01/2024, 1:50 AMfuture-hairdresser-70637
10/01/2024, 1:50 AMthis.initializeAndRegisterOutputs was added https://github.com/pulumi/pulumi/commit/342b80b7683356b022cb266a362c42ec4bd27f23#diff-2324dd338afb732d58bf71af19e[…]b841a80e03d9d659bd05cb411e7f30d3future-hairdresser-70637
10/01/2024, 1:51 AMfuture-hairdresser-70637
10/01/2024, 1:52 AMfuture-hairdresser-70637
10/01/2024, 1:52 AMsteep-secretary-65224
10/01/2024, 1:54 AM