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

lively-crayon-44649

08/18/2022, 9:25 AM
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

swift-ambulance-7102

08/18/2022, 5:54 PM
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

lively-crayon-44649

08/19/2022, 12:52 PM
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?
4 Views