Hey guys, has anyone tried to implement unique ids...
# python
d
Hey guys, has anyone tried to implement unique ids in the URN of the resource with pulumi python? I'm working on a project where we are handling a naming convention but we need something that pulumi can provide us to solve this. I'll keep an eye out if anyone knows :D
e
Not totally sure what your asking for here? All pulumi logical names must be unique, the engine will error if a program tries to register the same name twice. By default pulumi will append random characters to the end of physical names (what's sent to the cloud provider) to try and ensure global uniqueness.
d
Okay, I'll try to be a little clearer. I'm trying for example to do something like this:
Copy code
for subnet, nat_gateway in zip(
            subnets["subnets_objects"], nat_gateway_objects):

    private_route_table = RouteTable(
                f'myRouteTableExample-{region_suffix}',
    vpc_id=vpc.output.id,
    routes=[{"cidr_block": "0.0.0.0/0",
          "target_id": nat_gateway.id}])
Here I am trying to create several route tables dynamically, which I am iterating inside a for loop but the problem is that the resource_name would be the same and I would have to program something so that this resource_name is not repeated. What I want to know is if Pulumi provides a solution for this or should I implement something additional.
e
Yeh you need to do something custom there, probably putting the subnet and nat id's as part of the name or something
d
Ok, thanks for the quick response
e
Why wouldn't autonaming work here? Multiple
RouteTable
instances are created, and get postfixed, no?
e
They each need a unique logical name as well
Autonaming is for trying to keep resource physical names unique across multiple stacks, it's on you the programmer to ensure logical names are unique within one stack
e
It seems to me that autonaming could cover cases like these as well, in the future.
e
Maybe, but it starts getting into really hard to debug cases based on program ordering.
e
Combined with timestamped logging, it would work..
e
I don't think it would, logical names are used for state tracking and the timestamp or program order of them isn't a feature we can safely track by