https://pulumi.com logo
Title
r

red-lighter-44012

04/09/2021, 6:42 AM
I am often struggling to write reusable code and I think im doing something wrong. For example right now im provisioning a second database and migrating the main one to it. Something that could've been 3 lines of code ended up forcing me to copy paste a bunch of methods or add parameters because every resource URN ended up being a duplicate (including passwords). There should be a better way of doing this, but with the length limitations im struggling to find a good convention for URNs that can be done programatically (eg concatenating a couple of parameters).
b

brave-planet-10645

04/09/2021, 8:12 AM
Can you share some code? You shouldn't be seeing duplicate urns
r

red-lighter-44012

04/09/2021, 11:08 AM
The duplicate URNs are because im kinda manually setting them. I usually concatenate a couple of properties from the parameters and append some string to them, but in some scenarios I need to further differentiate. I was just wondering if I can follow some common rules of thumb so I can make my infra setup a bit more reusable. Eg creating the same schema in the {environment} database and in the {environment-just-doing-some-test} database gets quite complex as a lot of stuff is involved
I think I need to make up my mind how reusable my "CreateUserWithGrantOnSchema" methods (just an example) should be 😄
b

brave-planet-10645

04/09/2021, 11:10 AM
How come you're not letting Pulumi handle the naming for you?
r

red-lighter-44012

04/09/2021, 1:57 PM
I use pulumi's naming for things most things like resource groups or storage accounts, but not for db schemas or user accounts
also afaik every resource requires a unique logical (is this the right term) name. E.g.
pwd = new Password("pwd-foo-bar", ...)
the name I give here has to be unique
Which .. makes sense.
b

brave-planet-10645

04/09/2021, 2:54 PM
Sorry, yes you're right about the name there needing to be unique
If the length of the name is an issue, could you abbreviate it?