-
Notifications
You must be signed in to change notification settings - Fork 311
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
Allow hooks to calculate their arguments using resolvers #329
Comments
Thanks for the request @sodle. Will see if someone can pick this soon. |
Hey @ngfgrant, I'm interested in similar feature as well and willing to commit some time to investigate.
|
Any progress on that? |
@m1keil Option 3 sounds like a very good start and we could move quickly on it? |
@ngfgrant I can give it a go. Been some time since I looked at this issue. I'll update in few days. |
Thanks guys. |
Yeh V2 only please |
@Krzysztof-Szyper-Epam btw I believe you already have access to It's all accessible via
Should be probably something along the lines of:
|
@m1keil That's great. I'll test it when I have the time. So something like that should work?
|
In Sceptre 1.x we used a trick whereby we would add a custom field to the root of the configuration (e.g. # stack.yaml
...
hook_data:
upload:
s3_bucket_name: !stack_output_external platform-{{ environment_path.0 }}-infrastructure::LambdaCodeS3Bucket ...
from sceptre.resolvers import ResolvableProperty
...
class DeployCode(Hook):
resolved_hook_config = ResolvableProperty('resolved_hook_config')
def run(self):
self.resolved_hook_config = self.stack_config['hook_data']['deploy_code'] I've not tried to migrate anything like that to Sceptre 2.x, but the general approach could be something that could be worked into an implementation in the library (also iirc only |
I'm currently using v2 (newbie here) but i dont see any way to get outputs during a hook.
my yaml:
|
At the moment hook node type is ScalarNode only.
I have experimented with allowing other node types (sequences, maps) and fully utilise constructor arguments:
Obviously this change allows all sorts of types of objects appearing in the arguments (scalar only produces single string) including objects constructed by other resolvers, which can be a major concern, since this exposes a lot of data. Example:
|
You've not specified a try add ...
sceptre_user_data:
- welcome: hello world For everyone else Regarding hooks - you can access everything on a stack including its dependencies with # my_hook.py
...
self.stack.sceptre_user_data
self.stack.parameters
self.stack.dependenices # gives full stack objects with complete stack config of dependencies I can definitely see that having this functionality would be useful but I am not sure it is a wise thing to add in terms of maintainability and potential for debugging chaos. We do plan to rewrite how resolvers work so that they are a bit nicer to maintain and at that point we might look at doing this. Not settled on anything just yet but those are some thoughts. |
An approach to this was resolved in #140 but only ever made it into |
I am trying to pass the outputs of Sceptre stack_output_external resolvers to hooks and getting surprising failures, e.g.: hooks:
before_create:
- !cmd "./network/hooks/validate_cidrs.sh \
-p {{ var.PrimaryCIDRBlock }} \
-a {{ var.PublicSubnetCIDRa }},{{ var.PublicSubnetCIDRb }},{{ var.PublicSubnetCIDRc }} \
-b {{ var.PrivateSubnetCIDRa }},{{ var.PrivateSubnetCIDRb }},{{ var.PrivateSubnetCIDRc }}" And in my vars: PublicSubnetCIDRa: '!stack_output_external gitops-test-vpc::PublicSubnetCIDRa'
PublicSubnetCIDRb: '!stack_output_external gitops-test-vpc::PublicSubnetCIDRb'
PublicSubnetCIDRc: '!stack_output_external gitops-test-vpc::PublicSubnetCIDRc'
PrivateSubnetCIDRa: '!stack_output_external gitops-test-vpc::PrivateSubnetCIDRa'
PrivateSubnetCIDRb: '!stack_output_external gitops-test-vpc::PrivateSubnetCIDRb'
PrivateSubnetCIDRc: '!stack_output_external gitops-test-vpc::PrivateSubnetCIDRc' This is resulting in a failure:
I guess I am running into the same issue as this one? |
Me too, plus one, and all that. 👍 I bet there is a way to access stack outputs from inside a hook fired after that stack is created, but if there is, I can't figure it out from the docs. If someone knows how to do this, can you get me started? |
There is a crude way to do this. Basically, your hook calls a wrapper script instead of the actual command you want to call. The wrapper script calls I think this will work on all versions of sceptre, though I have only tested it on the version I'm using. Note depending on how you split up your stacks/stack groups, you may need to have reflective property names defined in your stack config to pass to the wrapper script. e.g. a property |
I want to be able to use a resolver (i.e. a CloudFormation stack output or a local environment variable) to calculate the arguments to a hook. For example:
Currently, these resolvers are not evaluated by the hook; instead, their literal text is executed, causing the command to fail.
The text was updated successfully, but these errors were encountered: