https://pulumi.com logo
#general
Title
# general
a

acoustic-monitor-21868

05/30/2022, 9:40 AM
Hi All, does pulumi supports a native way to apply some resources to a specific stack only?. Say I have 3 VM instances that I am preparing to be rolled out on staging stack only, and not yet ready to roll to prod stack, how can I enforce Pulumi to ignore these resources if someone do
pulumi up
on prod stack?
e

echoing-dinner-19531

05/30/2022, 10:21 AM
Not really. You can pass --targets to up to limit what things are changed but that doesn't sound like it would quite match this use case.
a

acoustic-monitor-21868

05/30/2022, 10:28 AM
Thanks a lot for your response!. What would be the best practice to achieve something similar? do I need to change the way I structure my environments? as I understood from Pulumi's docs I should put my environments into different stacks !
e

echoing-dinner-19531

05/30/2022, 10:30 AM
I think the general thinking is that you'd use different git branches or workflows for something like this. Like merge changes up to a prod branch once staging is good, or have a workflow that only updates prod with the latest code once staging has been updated.
q

quaint-hydrogen-7228

05/30/2022, 11:28 AM
You can have a config entries that defines VM properties for each environment (one or more stacks per environment), and that would include the number of instances. Your code would use these config entries to determine what to do.
l

little-cartoon-10569

05/30/2022, 8:53 PM
You can conditionally check the name of the stack, or use feature flags.
Creating a variable number of resources based on config is what the awsx Vpc does with subnets, and it causes awkward-looking boilerplate code later, when using those resources. From a code-tidiness point of view, I recommend against that option. Feature flags wrapping both the creation and use of these resources might work a little better.
What about putting the VMs in an ASG, and configuring the max/min size differently for different stacks? Set it to 0 for prod? (Don't know if ASGs can have max size 0... 🤔 )
e

elegant-zoo-39359

08/12/2022, 3:06 PM
Our stacks (dev/staging/prod) all have some differences, so I just select the stack in `main.go`:
Copy code
stack := ctx.Stack()
switch stack {
case "dev":
	return stacks.CreateDev(ctx)
case "prod":
	return stacks.CreateProd(ctx)
And they then select which of the shared resource-creation functions to call. We haven't got to a real release yet though, but I guess we'll have to go with Git tags to control gradual roll-outs of changes to each environment.
5 Views