-
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
Feature: String multiple resolvers together #1165
Comments
So I was looking into something similar, using resolvers as arguments to other resolvers, but YAML explicitly doesn't let you do that. I think the closest thing we could accomplish would be resolvers that operate a bit like CloudFormation resolvers that take list args, like how you can do something like this: Conditions:
MyCondition: !Equals [ !Ref FirstParam, !Ref SecondParam ] To accomplish what you are suggesting in Sceptre, you could do something like: parameters:
SortedStaff: !chain
- !file staff.txt
- !sort. # The resolved value from !file would be passed as the argument to !sort. Notice how this isn't !rcmd In order for this to work, however... the !chain resolver would need to:
The problem with your example is that you're passing |
You're right @jfalkenstein and you've read my mind. Your example is what I really meant, chaining multiple resolvers together. I like your idea however it seems like it's a lot of work though. I'm wondering if we can get this same functionality by creating and using custom jinja functions. I'm thinking it would be something like this..
although i'm not sure how we would register and load that custom jinja based GetFile function. |
Well, with the j2_environment parameter, I suppose we can load Jinja extensions. One way would be to just make an extension. I've thought about making resolvers available in the jinja environment before. Something like However, the issue with using resolvers in ninja is that Jinja is rendered BEFORE the config is rendered and this before the stack exists. I don't think the timing would allow resolvers to operate before the stack exists. |
Alternative, we could just prepopulate the Jinja environment with a module of useful utility functions that augment what Jinja already provides. I've really wanted functions for hashing, for example. We could also have some for getting file contents, stack outputs, and a few other useful ones too. |
@zaro0508 I just had an idea on this one. Imagine this: template:
path: mystack.yaml
stack_name: mystack
parameters:
SortedStaff: !pipe "!file staff.txt | !rcmd sort" I think this could work. Since, by the time this is loaded, we would have already added the yaml resolver constructors to the loader, we could the def resolve(self):
piped_segments = self.argument.split('|')
result = None
for segment in piped_segments:
resolver = yaml.safe_load(segment.strip())
resolver.stack = self.stack
if result and resolver.argument is None:
resolver.argument = result
elif result:
resolver.argument += f' {result}'
resolver.setup()
result = resolver.resolve()
return result In other words, the result of prior resolvers is used as (or appended to) the arguments of the latter ones. The argument to What do you think of this idea? |
@zaro0508 You never did respond to this one. What do you think of my idea here ^^? |
hmm, a |
This is fixed with PR #1313 and available in sceptre v4.1.0 |
This is a feature request. I would like to be able to string multiple sceptre resolvers together to return one value for a parameter. The idea here is similar to
ls –al | more
on linux systems.Here's a trivial example of resolving a parameter by getting the contents of a file and then sorting it before assigning it to the
SortedStaff
parameter:Assume staff.txt contains:
Upon
sceptre launch
, SortedStaff would contain:The text was updated successfully, but these errors were encountered: