With Javascript, if I have 3 files importing a vpc...
# general
With Javascript, if I have 3 files importing a vpc resource from a vpc.js file - will it create 3 different VPCs? Or will it share one VPC? I'd like for it to share one VPC but able to abstract the VPC out into a file that other files can share.
I have guesses, but haven't tested this: waiting for answers. 🙂
It will create and share the one vpc.
Someone else can articulate it better than me, but the way imports are handled it will essentially result in one vpc getting created and shared.
Ah thanks! Must be a state mismatch issue on my end then 🙂
[pure speculation] it probably depends on how you're consuming the vpc.js~ - if you're consuming it from multiple states, it's going to create one per state. if it's from the same state, it's going to know about it. I think there's some way to share state/state knowledge, but I haven't gotten back to that problem myself yet.
er, stack, not state.
The example I posted is for using a single
in a single Pulumi application.
The VPC created will be scoped to the current stack that's selected.
So yes, if you create and select a different stack, it will create a different VPC.
ahh thanks!
So nodejs imports are Singletons
Subsequent imports will point to the same object in memory that was instantiated the FIRST time it was imported.
Well, yes and no.
Depends on what you export.
The better way to think about this is that you’re creating a single object and exporting it. If you created a function that returns a VPC and called it multiple times you’d get multiple VPCs.
⬆️ 1
ahhhh icic, cool!