cloudtools / stacker

An AWS CloudFormation Stack orchestrator/manager.
http://stacker.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
709 stars 167 forks source link

Dynamic Stack Names #629

Closed Spareo closed 6 years ago

Spareo commented 6 years ago

I am trying to implement stacker into an existing architecture by having it replace our manual CF creation process. One thing we do is format stack names in a specific way that uses the current branch and commit hash. Is there a way in stacker for me to set a stack name at build time by using a lookup or hook?

I have been going over the source code and documentation but can't seem to find any way to go about this.

ejholmes commented 6 years ago

Easiest way to do this is generate your stacker config file before passing it to stacker. We do something like this at Remind:

$ ./stacker.yaml.py | stacker build -

Where stacker.yaml.py is a little python script that generates our stacker config file. There's really nothing you can't do with stacker using this approach, since you have the full power of the unix pipeline at your disposal.

Spareo commented 6 years ago

Yeah I was thinking that is where I would have to go to get what I wanted. I was just holding out hope for some magical function I was overlooking.

Thank you!

phobologic commented 6 years ago

@Spareo one thing to keep in mind - if you keep changing the name of the stack, stacker will not remove the old stack automatically for you - it only keeps track of the stacks in it's config. So if you start with namespace-my-stack-sha1 and then run build again with it changed to namespace-my-stack-sha2, it'll create a whole new stack, but the sha1 stack will still remain.

This is to avoid stacker thinking it owns all the stacks in an account - though there's a PR right now for deleting stacks that are in stackers namespace but no longer in the config.

Spareo commented 6 years ago

We already have other CI scripts in place that handle the clean up. I just need something that can generate CF templates and share variables/outputs across stacks. Thanks for the info though!

mchristen commented 6 years ago

I know this is closed already but there's an easy hack/workaround for dynamic stack names.

You can use the env substitution mechanism to supply stack names, for example.

name: test-stack-${commit_hash} or even something like name: ${dynamic_stack_name}

then all you need to do is set those appropriately in the env file which can be done during runtime and you get to avoid having to generate entire yaml configs.