Hey all; I'm wondering if anyone has any patterns/...
# general
l
Hey all; I'm wondering if anyone has any patterns/tips when it comes to sharing and hydrating resources across stack boundaries/using stack references. Currently, I'm thinking that a good idea might be to adopt a pattern where my `ComponentResource`s look something like this:
Copy code
class MyResource extends pulumi.ComponentResource {
  static create(name, args, opts): MyResource {
    const foo = new aws.Foo(...)
    const bar = new aws.Bar(...)

    return new this(foo, bar)
  }

  static fromExisting(fooId, barId) {
    const foo = aws.Foo.getFoo(fooId)
    const bar = aws.Bar.getBar(barId)

    return new this(foo, bar)
  }

  private constructor(foo, bar) {
    this.foo = foo
    this.bar = bar
  }

  toOutputs() {
    return {
      fooId: this.foo.id,
      barId: this.bar.id,
    }
  }
}
s
This is something I go back and forth on. I think it depends on the team and their maturity level. I tend to learn more towards packaging it all up into one pattern that does most of the heavy lifting. The struggle is how many deployments you want to do and or tolerate.
l
Thanks for the reply! Yes, I agree about maturity. Is what I've written along the same lines as the approaches you've tried/seen, or am I way off base?