https://pulumi.com logo
Title
w

worried-queen-62794

04/11/2021, 9:24 PM
I feel like I may have asked this before but is there a reason why a resource does not expose its name?
l

little-cartoon-10569

04/11/2021, 9:27 PM
Probably not a reason per se: the name of a resource is the key in a map. The value (resource object) doesn't really need the key.
The name is essentially part of the state, rather than part of the resource.
w

worried-queen-62794

04/11/2021, 9:28 PM
It would be really useful when creating resources based on other resources.
l

little-cartoon-10569

04/11/2021, 9:28 PM
In a ComponentResource? I just pass the name straight through.
Or sometimes append something to it.
w

worried-queen-62794

04/11/2021, 9:28 PM
Yes of course that's what I want to do but then you end up having to push this extra parameter around and duplicate it all over the place
I'll show you an example, one minute
l

little-cartoon-10569

04/11/2021, 9:30 PM
If you're constructing resources outside of the constructor, yes, you do currently have to do that 😞 Unless maybe you can duck-type the name somehow?
Yep, looks like this might be worth a try if you don't mind sneaking under the covers:
const internalName = (resource as any).__name;
w

worried-queen-62794

04/11/2021, 9:31 PM
Oh yeah cool that will do.
Thanks
👍 1
l

little-cartoon-10569

04/11/2021, 9:33 PM
Usual caveat: may break without warning. Undocumented internal code. Etc.