-
Notifications
You must be signed in to change notification settings - Fork 165
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
Resolve lookups in hook args #708
base: master
Are you sure you want to change the base?
Conversation
Hope this gets merged soon, this would be a super useful feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay - dug into this this weekend, and it looks pretty good. One big concern (which I put inline) and also I think we'll need docs to detail how to use this, it's limitations, etc.
Thanks!
enabled = hook.enabled | ||
|
||
if isinstance(hook.args, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea how this would work with the output
lookup, which changes the order of execution? I think it will likely break- especially if it's a pre_build hook that runs before the graph gets executed. Even with that, I think this is still good - we just might want to handle that case, and explicitly indicate somehow that lookups that change the order of execution can only run as post_build hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested output with a post_build hook, it works as expected. However, you are right that it does not work in pre_build. It raises FailedVariableLookup and uses the closest key in args as the variable in the exception.
I added a log output that explains the use of output and similar lookups in args. With the condition used it won't trigger for failed lookups that include another exception like StackDoesNotExist. If you have a better idea, please let me know. I avoided checking the lookups provided here before trying to resolve them here to not add time. could maybe pass stage to resolve_variables/Variable.resolve() if we do want to add validation logic around it?
Hey @ITProKyle - thanks for this. I think we might want to hold off on it in favor of #722 however, as that does this + adds the ability for hooks to be put directly into the execution graph, so you no longer only have pre/post build hooks. What do you think? |
@phobologic - that works. I haven't dug too deep into #722 yet to see how it's being done but as long as lookups can be resolved natively in hook args - that's all that matters. |
Is there something still holding this back from getting merged? This would make lookups 1000% more useful in my opinion. |
I'd love to see this merged as well! |
Any updates on this or details on what it will take to get it merged? If its not much I can try to finish it up. |
@Spareo this was paused because of a pending refactor of how hooks work that should take of this. In the meantime, I have been added something similar to what is below to all my custom hooks which effectively does the same thing as this PR. However, it wouldn't help with any of the built-in hooks. import logging
from stacker.variables import Variable, resolve_variables
LOGGER = logging.getLogger(__name__)
def get_variables(variables, provider, context):
converted_variables = [
Variable(k, v) for k, v in variables.items()
]
resolve_variables(
converted_variables, context, provider
)
return {v.name: v.value for v in converted_variables}
def example_hook(provider, context, **kwargs):
"""The function being called as a hook."""
variables = get_variables(kwargs, provider, context)
for k, v in variables.items():
LOGGER.info('%s: %s', k, v)
return variables |
closes #688
This change allows for the resolution of all
stacker.lookups
passed into a hook's args without needing to add a handler to each hook.Previously, only lookups to the provided
.env
were resolvable or logic had to be added to hooks individually to handle lookups.Example Usage
Output