I'm playing with component resources and looking at urn. Here's my little test app: ```class Example...
l
I'm playing with component resources and looking at urn. Here's my little test app:
Copy code
class ExampleAppCloudResources extends pulumi.ComponentResource {
    randomResource: random.RandomString;
    anotherRandomResource: random.RandomString;
    public readonly secretString: pulumi.Output<string>;
    constructor(name: string, opts: pulumi.ComponentResourceOptions) {
        super("ExampleAppCloudResources", name, {}, opts);
        //console.log("ExampleAppCloudResources constructor");
        this.randomResource = new random.RandomString("random", {
            length: 16,
            special: false
        }, { parent: this });
        this.secretString = this.randomResource.result;

        this.anotherRandomResource = new random.RandomString("another-random", {
            length: 16,
            special: false
        }, { parent: this });
    }
}
Copy code
var exampleApp = new ExampleAppCloudResources("test", {});
var exampleApp2 = new ExampleAppCloudResources("test2", {});
export const secretString = exampleApp.secretString
I would guess pulumi would generate urns based on the component resource "type" and id, but it only generates it based on the type, causing collisions here. To me that seems like a strange design choice, it would make everything more robust with less chance of urn collisions if the entire "tree" was taken into account. Does anyone know how I can control this? I'd hade to have to add
{name}
as a prefix to every single resource in my component resource. Is there some global setting that can auto-prefix for me?
I guess I found my answer in the bottom here: https://github.com/pulumi/pulumi/issues/20573 Very unfortunate design choice
e
To me that seems like a strange design choice, it would make everything more robust with less chance of urn collisions if the entire "tree" was taken into account.
Yes 😞 a very unfortunate early decision that we're currently stuck with.
Does anyone know how I can control this? I'd hade to have to add
{name}
as a prefix to every single resource in my component resource. Is there some global setting that can auto-prefix for me?
Not currently. The advice is to just prefix your component resource name to every child resources name. We really want to change this but the amount of code that depends on the current format of URNs is vast
l
thanks! How about adding a project-level feature flag defaulting to the "Old" behavior so that at least greenfield projects would not have to suffer from this?
e
I'll give that a thought, not sure if the blast radius of this is constrained to single projects
l
I'm not sure if I understand but as I don't know much about the pulumi codebase there's probably nuances to that that I'm not able to see.
l
I came across this when I started testing out Pulumi and thankfully I caught it early enough into adoption that I was able to create a base component class that extends pulumi.ComponentResource that includes the name in the type, and all of our custom components extend from that
Copy code
super(`ebx:component:${type}/${name}`, name, args, pulumi.mergeOptions(opts, ourOpts))
This almost certainly breaks some assumptions within pulumi, but it has worked consistently for over a year now
❤️ 1
e
As long as your names don't have dollars or colons in them you'll probably be ok with that