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

average-dream-51210

06/04/2019, 8:54 PM
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.
p

proud-alarm-92546

06/04/2019, 9:09 PM
I have guesses, but haven't tested this: waiting for answers. 🙂
g

gentle-diamond-70147

06/04/2019, 9:18 PM
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.
a

average-dream-51210

06/04/2019, 9:48 PM
Ah thanks! Must be a state mismatch issue on my end then 🙂
p

proud-alarm-92546

06/04/2019, 10:05 PM
[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.
g

gentle-diamond-70147

06/04/2019, 10:36 PM
The example I posted is for using a single
vpc.js
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.
a

average-dream-51210

06/05/2019, 12:38 AM
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.
i

important-carpenter-15282

06/05/2019, 2:05 AM
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
a

average-dream-51210

06/05/2019, 3:43 AM
ahhhh icic, cool!