Add support for pre/post-apply/delete actions
It would be great if stacks could be setup so certain actions (or hooks) could run before and after applying and deleting them.
In my head, indicating the actions would be done in the stack_master.yml itself. Something like:
stacks:
us-east-1:
my-s3-bucket:
pre_apply: delete-if-exists.rb
post_apply: print-outputs.rb
pre_delete: delete-bucket-contents.rb
post_delete: notify-admins.rb
- On a very basic version, we would be talking about executable scripts in any language that would receive as parameters:
| Action | Parameters |
|---|---|
pre_apply |
The compiled CloudFormation JSON template to be applied and parameter values. |
post_apply |
The compiled CloudFormation JSON template that was applied, parameter values and output values. |
pre_delete |
The compiled CloudFormation JSON template to be deleted, parameter values and output values. |
post_delete |
Same as pre_delete. |
-
If the script returns zero, then
stack_masterwould continue execution. Any non-zero return code would interrupt the execution. -
Actions would be located under an
actionsdirectory at the same level asparameters,templates, etc.
Thanks for writing this up @samuelsuarezsanchez!
I like the proposal :)
Here's some feedback:
- consider grouping all the "command hooks" under
hooksorcommand_hooksinstead of directly under the template name. - an extension would be to support all/other commands other than
applyanddelete. - consider renaming the
actionsdirectory tohooksorcommand_hooks. - depending on use case, it may be preferable to always execute the
post_<command>hooks regardless if the exit status of thepre_<command>hooks. In this case, a "command status" parameter is passed to the post hooks. For example, the post hooks could be used for some cleanup of the pre hooks that you always want to run. - should post command hooks be executed if the command fails?
To be clear, I'm not suggesting increasing the scope of this proposal, just some things to think about so it can be extended in the future :)