I’m wondering if anyone can help me figure out a w...
# general
d
I’m wondering if anyone can help me figure out a way to create a stack on-the-fly in our CI/CD process. I’d like to create an “ephemeral” stack for in progress work on git branches of our application repo. I’ve designed a stack that I’d like to be able to “clone” or create a version of. Let’s say the “reference” stack is called “dev” (I don’t actually want any aws resources created for “dev”, it is merely the reference):
Copy code
# Pulumi.yaml
name: app-ephemeral
runtime:
  name: python
description: Branch-based ephemeral environments

# Pulumi.dev.yaml
environment:
  - app-ephemeral/dev
Here’s the thing though… the Pulumi code is in our infrastructure repo. I have a system already set up that leverages Pulumi Deployments via the REST API to trigger deployments of our staging and production environments… but those stacks already exist. For this, I need to 1) create the stack, 2) set the configuration, and then 3) trigger the deployment. I’m ok with #1 as I can create the stack with the automation API:
Copy code
stack = auto.create_stack(
        stack_name=auto.fully_qualified_stack_name("myorg", "app-ephemeral", "my-branch"),
        work_dir=".",
    )
I just can’t figure out how to set the config for this stack to inherit from the main environment… Anyone have any ideas? Or thoughts on a different approach?
l
Lots of ways to do it. I've been browsing the Pulumi blogs, seems like there's quite a few opinions about it. I haven't had a play with them yet, but Review Stacks sound like the feature you want. https://www.pulumi.com/blog/review-stacks/
d
Ahh I’ve looked at them, but more so from the perspective of testing changes to infra rather than changes to our Django application code. Right now our infrastructure code is in a separate infra monorepo from our Django apps (we have several Django apps in separate repos). I think it would be a pretty major overhaul to use review stacks for branches on our application repo… I’d love to see if there is another way to create / “clone” a stack…
l
Ah. Are they containerized apps running on some sort of scaling infra, like k8s or an ASG? If they are, you may not need (or want) a new target environment, and instead you may want to leverage the usual "redeploy from registry" functionality of your runtime.
Pulumi can do this of course.. but should it?
If they're an old-school style, essentially "on-prem" deployment to EC2+API gateway, then a new stack is a reasonable solution. Not a problem I've solved before, sorry. But maybe moving as much config to Pulumi.yaml as possible? Anything in there is inherited by all stacks within the project.
d
Unfortunately the applications are a bit more complicated. It’s a whole set of resources — database, AMQP, redis, s3, multiple containers… I’d like to deploy the whole thing
Is
environment:
supported in the main Pulumi.yaml? It doesn’t seem to be taking that config
l
Couldn't tell you, haven't tried that and not currently using ESC. #C0602S4P4T1 would be the place to ask, I think?
You can of course run Pulumi from ESC. That would remove the need for that configuration.
d
I think ended up figuring out an approach here… if it works, will report back 🙂