Hi, is there any easier way of referring to resour...
# general
b
Hi, is there any easier way of referring to resources in my same project? I was using stack references bit it seems weird to use a stack reference to get an output for my same project. The output I', trying to get was something created in a different package (python). I tried to create a stack reference again, but it failed saying I have to give it a unique name. It definitely seems a lot a lot work to just refer to a resource I created in my same project just in a different package. Any suggestions?
m
@bitter-postman-79233 it's an interesting idea. However, if we have the same resource names in two different stacks in your project, it will be hard to understand what resource we changed. Today, resource names are based on stacks that are part of projects. Maybe an alternative could be created at another level, e.g.,
groups
or
workspaces
, to allow such cases to group resources for other dimensions.
Another approach could be using tags, that recently Pulumi added.
l
Referring to resources between stacks of the same project suggests that the design could be improved. If (e.g.) your prod VPC needs peering to your dev VPC and both VPCs are defined in stacks of a single project, then the peering probably shouldn't be in that project at all. It should be in a different project that can see both stacks.
b
In my case is same stack/project (python). I have a resource (resource-1) that was created in a package A. 2 days later I decided to create another resource (different) that needs an output from resource-1. How do I get such output?
l
Just use it. No need to use stack references.
No need to use apply, if you're passing the output to the constructor of another resource.
b
That forces me to create a coupling between the 2. Resource-1 needs to know everything that needs it. If you have several dependencies around it becomes a dependency hell for sure
l
If the two resources are in the same project, then they're not external dependencies. Just variables. You may even want to put the resources in a component resources, to tie them even closer.
If it's really important to you to inject the dependency, then inject it in the normal way. I'll whip up a quick TS example.
b
Thank you, that would be helpful
l
Sorry it's TS, I have almost no Python knowledge.
b
Thank you, I appreciate it. It's ok, the idea is transferrable between languages. A minor detail
l
Both options are in the example. I recommend the strongly-typed 1st option if the resources can't feasibly be created in any other code (it's a real "internal" dependency). The 2nd option injects just the string property value, and I'd use it if the resource is created outside of the same project.
b
I just ended up creating a Singleton class to contain a "registry/map" of all objects I need to declare. So that any interested party can call it by name