https://pulumi.com logo
#general
Title
# general
m

magnificent-helicopter-3467

07/06/2022, 5:18 PM
Hi team, I’m wondering what registering resource outputs for a pulumi component does. It’s not too clear to me from documentation whether this is cosmetic or necessary for a pulumi component to be functional. If we have a
ctx.RegisterResourceOutputs(<component>, resourceOutputsMap)
at the end of our component’s constructor but before the return, will this call ensure that all values in
resourceOutputsMap
resolve before proceeding? I don’t see anything visual during
pulumi preview
in
Outputs
when adding this call (just the usual exports). Any help in understanding this method would be appreciated, as I’m debating whether or not I should call it.
b

billowy-army-68599

07/06/2022, 5:20 PM
it's currently cosmetic, but you should call it as it lets the component know that all outputs have resolved
m

magnificent-helicopter-3467

07/06/2022, 5:23 PM
I see. Am I calling it the right way? I read about apply in Pulumi, but I wonder if the return in my first function could potentially execute before the apply callback in second function is executed (during resource provisioning). For reference, here’s my go code:
Copy code
func NewMyComponent(ctx *pulumi.Context, name string, opts …pulumi.ResourceOption) (*MyComponent, error) {
  
  // infos is a []pulumi.StringOutput in format "output_key1=output_value1;;;output_key2=output_value2…"
  addInfoToOutputs(ctx, myComponent, infos)

  return myComponent, nil
}

func addInfoToOutputs(ctx *pulumi.Context, myComponent *MyComponent, infos []pulumi.StringOutput) {
  pulumi.All(infos).ApplyT(
    func(args []interface{}) error {
      var outputs pulumi.Map
      for _, arg := range args {
        s := strings.Split(arg.(string), ;;;)
        for _, element := range s {
          pair := strings.Split(element, "=")
          if len(pair) != 2 {
            return errors.New(fmt.Sprintf("Expected computed output pair to be of length 2, but got length %v", len(pair)))
          }
          outputs[pair[0]] = pulumi.String(pair[1])
        }
      }
      err := ctx.RegisterResourceOutputs(myComponent, outputs)
      if err != nil {
        return err
      }
      return nil
    },
  )
}
b

billowy-army-68599

07/06/2022, 5:25 PM
I personally would not call that from a function, but that looks functionally correct yes
👍 1
m

magnificent-helicopter-3467

07/06/2022, 5:26 PM
Is there any feedback I should be able to see from
pulumi preview
letting me know that
RegisterResourceOutputs
actually ran?
b

billowy-army-68599

07/06/2022, 5:29 PM
not in preview no, preview doesn't know about outputs
m

magnificent-helicopter-3467

07/06/2022, 5:30 PM
Right makes sense. I guess that would only resolve after actual provisioning — thanks for your help 🙂
b

billowy-army-68599

07/06/2022, 5:31 PM
yeah, outputs only resolve once the cloud provider returns values
👍 1
3 Views