Is there a best practices when naming resources in...
# general
g
Is there a best practices when naming resources inside of a
ComponentResource
to prevent URN conflicts? It feels repetitive to have to include some sort of prefix for multiple instances of the ComponentResource..
Untitled.cpp
For example, if I do not use the base_name as part of the resource_str of the child resources, I get a conflict when instantiating FooVpcComponent. Maybe this is by design and it's my responsibility to ensure this uniqueness? Just thinking from Terraform, where these resources would be unique to the module scope... in Pulumi's case it seems like the ComponentResource's
name
isn't actually used as part of the URN constructor... or I'm doing something wrong....
I was thinking of putting the name for the super constructor of
f"foo:aws:FooVpcComponent:{name}"
but all the examples I saw only show 3 components for that value and so I felt like that was not the right way to do this...
l
Why do you need to change the type? So long as the name is always different, all should be good.
The type is constant for a ComponentReosurce. The name (1st parameter to the constructor) changes. All resources created within the ComponentResource must use that name (or something derived from it) as their name.
if I do not use the base_name as part of the resource_str of the child resources, I get a conflict when instantiating FooVpcComponent. Maybe this is by design and it's my responsibility to ensure this uniqueness?
Exactly.
g
I do not need to change the type, I was just wondering if that was expected or I was just doing something else wrong. Thank you for the info
So my conclusion is that I need to still ensure uniqueness of the resource_str for child resources across all instances of the ComponentResource of the same name.
👍
BTW just following up here: I found way at the bottom of the Resource URNs documentation, a little excerpt on what I was asking and confirms this. https://www.pulumi.com/docs/intro/concepts/resources/names/#urns
Copy code
Resources constructed as children of a component resource should ensure their names are unique across multiple instances of the component resource. In general, the name of the component resource instance itself (the name parameter passed into the component resource constructor) should be used as part of the name of the child resources.
🙏