https://pulumi.com logo
Title
b

billowy-tiger-6272

11/23/2022, 2:50 PM
I notice in the .NET version (the only one I use) that when you create, for example, a ResourceGroup for Azure, you do something like
var resourceGroup = new ResourceGroup("resourceGroup");
, but this will generate a resource group with a random name, and that if you want to give a fixed name you need to specify it in the
ResourceGroupArgs
class... But then we end up having like 2 instances of the resource "name"... How is this supposed to be handled correctly? I'd like to reduce code duplication (mainly if I'm interpolating the resources names based on the environment and such, but having to do twice for every resource looks kind of weird... Perhaps I'm misusing it... 🤔
l

little-library-54601

11/23/2022, 3:02 PM
I'm just about the furthest thing from a Pulumi expert. I started out trying to not use the random suffixes. In the end, I think it's best to let Pulumi generate those random suffixes where it needs to. I use "tags" (Azure) to add information to the various resources, e.g.
Tags =
{
    { "environment", "Development" },
},
e

echoing-dinner-19531

11/23/2022, 4:28 PM
There's some docs on this at https://www.pulumi.com/docs/intro/concepts/resources/names/ The two names are different names, we call them the logical and physical names. Our default behaviour is to use the logical name plus a random suffix for the physical name as that seems to work well for the majority of use cases. We do have an issue (https://github.com/pulumi/pulumi/issues/1518) to track providing a way to globally configure that.
b

billowy-tiger-6272

11/23/2022, 4:45 PM
Hmmm, I see... In many projects I work with Terraform, they create the resources with suffixes or at least a part of the name that explains what environment it belongs to, in order to more easily visualize that at a glance when looking at the resources list of a subscription...
Is there a better way to do this?
Or they're just different ways?
e

echoing-dinner-19531

11/23/2022, 5:20 PM
Just different, once we work out a good way of doing 1518 that'll probably support a load of different ways in a first class sort of manner, but for now the random suffixes work for most cases and you can override the physical names of resources as well if you want, although it is a bit more code to setup.
i

icy-doctor-13719

11/25/2022, 3:23 PM
I don’t like the randomness … I do this on every resource:
ResourceGroupName = $"rg-{p.projectName}-{p.env}"
b

billowy-tiger-6272

11/25/2022, 4:51 PM
Yeah, I have to agree that I don't like it either and that, like many pointed out in #1518, many places use to establish conventions for how the resources are going to be named. It's not the same looking at a notification about a resource having an issue and its name being a random one, than looking and knowing at first glance that it's an app service, for a given service/project, from a given environment...
b

bored-activity-40468

11/26/2022, 11:30 PM
I use Harmony to make a hook/callback so I can set the names using different naming strategies. Until 1518 is hashed out. I also use to not lie the randomness but now almost require it if the resource is at a level it could collide with other resources. It also forces me to lay the infra out in a way where several can be stood up side by side.