If I correctly understand the Pulumi docs on its a...
# getting-started
l
If I correctly understand the Pulumi docs on its architecture and the concept of a stack ("an isolated, independently configurable instance of a Pulumi program"), a single Pulumi program should be able to be used to create multiple "environments" (as we'd use the term: dev, test, uat, production). For that to be true, the resource names specified in the Pulumi program (C# for us, the class derived from "Stack") have to be unique for each environment. What is Pulumi's vision or recommended practice for how to accomplish that (the examples I've seen don't demonstrate this). 1. Is there a way in our Stack class to determine the currently active stack (i.e. what "pulumi stack" would output as the current stack)? 2. If not (or perhaps even if there is), should we use the Pulumi configuration mechanism, as documented at https://www.pulumi.com/docs/intro/concepts/config/ to let our Stack class know the target environment so that we can ensure unique resource names? Thanks.
e
Pulumis default behaviour is to set the resources cloud name to a user set logical name + a pusdorandom suffix. See https://www.pulumi.com/docs/intro/concepts/resources/names/#autonaming for more details.
l
Thanks for the reply. And that pseudorandom suffix (I was aware of that) will automatically change (or be different) when I change pulumi stacks (pulumi stack select)?
e
Yes its recently changed it used to be it was just random bytes from the operating systems crypto services, it's now a hash of stack name, resource name, and a count of how many times this resource has been re-created in this stack.
l
That's helpful. It would still make the environments to which a resource "belongs" opaque (i.e. in the web portal). I'm thinking I still might include an indicator in the resource group (Azure) so we can quickly look at a resource's resource group and know what environment it is. Thanks again.
b
You can typically get the current stack. In Go, it would be
ctx.Stack()
, but I imagine itโ€™s available in other programs.
l
I've looked all over for that in C# - haven't found it yet. But I'm guessing you're right.
b
Copy code
var stack = Deployment.Instance.StackName;
m
you probably don't want to introspect on stacks too much and let the configuration per-stack drive the differences transparently
if you are asking yourself "i want to do something different if it's this stack", and it can't fit in a config, you might want to think about how your project is organized and if you actually need a new project
๐Ÿ‘๏ธ 1
l
The resource names shouldn't have to be unique except in cases where the Cloud service makes that requirement and they're not namespaced appropriately. This happens for S3 buckets, but not a lot of other resources. Generally, Pulumi autonaming is sufficient. If you want the stack to be obvious on a resource, tags are usually the best option.
๐Ÿ‘๏ธ 1