This message was deleted.
# general
s
This message was deleted.
g
I made one
My use was for enabling the apis on GCP projects, but is the same concept. One moment, let me get you the link.
b
how does this work? it loads the resources from another project into the current project?
g
The
Singleton
creates a resource only when it is actually used, and only once. The service shows how to do that for on demand things
Your use would be making a component that creates the vpc, k8s and other things that you need
Then you would create an instance of it like the
projectService
function and on your code, suppose you name it `myInfra`:
Copy code
const infra = myInfra('customer1');

// Uses
infra.vpc
infra.cluster
...
And wherever you call
myInfra('customer1')
you will use the same infra
If you use another name, you would have a different infra
And once all the uses of
myInfra('customer1')
are removed, the resource is also removed
Did I make myself clear?? I think I made it more confusing than it actually is...
b
but all your resources are still in the same stack in that case, right? if you use the same infra code in separate projects (so separate stacks), do they both show those resources as being part of the stack? i guess that would make sense simply based on what a singleton is conceptually.
g
Yes, that Singleton is only for one stack, if you make 2 stacks they would be recreated. Two stacks are isolated unless you make them connect through either getting a resource created by another stack or using stack reference
You can combine that with the Singletons that I made, those are to help layered deployment within a single stack
Also you can use the singleton with the resource getter
myInfra('customer1')
could build a resource or get one, no difference. It would work the exact same way
b
yeah, "duplicating" resources like that is something i hadn't considered actually, i was thinking more like chaining `pulumi up`s for multiple stacks/projects.