Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate command does not execute hooks #874

Closed
zaro0508 opened this issue Dec 27, 2019 · 2 comments
Closed

generate command does not execute hooks #874

zaro0508 opened this issue Dec 27, 2019 · 2 comments

Comments

@zaro0508
Copy link
Contributor

zaro0508 commented Dec 27, 2019

I use the !cmd hook in my main and dependent sceptre files to download shared templates. In my case the sceptre generate command fails because it does not run the hook to download the needed CFN template files for sceptre to process. Is there a way to force the generate command to execute hooks? Just a note that when I run the launch command the hooks are executed.

Here's a simple example:

in templates/noop.yaml

Description: noop template
AWSTemplateFormatVersion: 2010-09-09
Resources:
  touchNothing:
    Type: AWS::CloudFormation::WaitConditionHandle

in config/prod/A.yaml

template_path: "noop.yaml"
stack_name: "A"
hooks:
  before_create:
    - !cmd "echo test before_create for A"
  before_update:
    - !cmd "echo test before_update for A"

in config/prod/main.yaml

template_path: "noop.yaml"
stack_name: "main"
dependencies:
  - "prod/A.yaml"
hooks:
  before_create:
    - !cmd "echo test before_create for main"
  before_update:
    - !cmd "echo test before_update for main"

execute generate:

sceptre --debug --output yaml generate prod/main.yaml

*Note: the output does NOT contain test before_create for A and test before_create for main which means the hooks did not get executed.

execute launch:

sceptre --output yaml launch prod/main.yaml 

*Note: the hooks do get executed and the output does contain test before_create for A and test before_create for main

@ngfgrant
Copy link
Contributor

ngfgrant commented Feb 3, 2020

Maybe worth a quick PoC: https://github.com/Sceptre/sceptre/blob/master/sceptre/plan/actions.py#L564 suggests that generate won't respond to hooks because it is not decorated with the @add_stack_hooks decorator like launch is (https://github.com/Sceptre/sceptre/blob/master/sceptre/plan/actions.py#L176).

Could you fire up a branch that has that change to see if it works without much hassle?

zaro0508 added a commit to zaro0508/sceptre that referenced this issue Feb 10, 2020
This enables `before_generate` and `after_generate` hook actions to
allow users to execute hooks when running the `generate` command.
zaro0508 added a commit to zaro0508/sceptre that referenced this issue Feb 10, 2020
This enables `before_generate` and `after_generate` hook actions to
allow users to execute hooks when running the `generate` command.
@zaro0508
Copy link
Contributor Author

thanks @ngfgrant, adding the decorator works.

zaro0508 added a commit to zaro0508/sceptre that referenced this issue Aug 28, 2020
This enables `before_generate` and `after_generate` hook actions to
allow users to execute hooks when running the `generate` command.
thawkson pushed a commit to thawkson/sceptre that referenced this issue Feb 6, 2021
This enables `before_generate` and `after_generate` hook actions to
allow users to execute hooks when running the `generate` command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants