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

add cf value of "current" stack to template vars #21

Merged
merged 2 commits into from Jun 15, 2017

Conversation

jaffee
Copy link
Contributor

@jaffee jaffee commented Jun 14, 2017

This gives templates a way to reference the parameters under "cf" in a stack the
config file without referencing a stack name directly. The "currentstack" key in
the map passed to the template will contain the "cf" map of the stack which is
being generated.

In this way, a single template can be used by multiple different stacks and have
different outputs.

If you can think of a cleaner way to achieve something like this, please let me know. I'm also very open to changing the name "currentstack".

I'd also like to call out that this could be a backwards incompatibility if someone had a stack named "currentstack" already.

This gives templates a way to reference the parameters under "cf" in a stack the
config file without referencing a stack name directly. The "currentstack" key in
the map passed to the template will contain the "cf" map of the stack which is
being generated.

In this way, a single template can be used by multiple different stacks and have
different outputs.
@daidokoro
Copy link
Owner

Hey Matt, thanks for this.

I believe I implemented something similar, you're able to reference which stack is calling a template by using {{ .stack }}, this however, only gives you the name of the stack calling the templates, you would need to use if-statements to swap values.

I think your method is better as the values are also accessible using {{ $.currentstack.etc }}.

So i'd recommend, overriding my {{ .stack }} functionality with this. Should just be removing line 632 in stack.go and changing currentstack to stack.

Thanks again :-)

@jaffee
Copy link
Contributor Author

jaffee commented Jun 15, 2017

I've made that change:

I like the simplicity of your suggestion, but are you concerned that there will no longer be access to the current stack name?

I'm also hesitant since this is a breaking change to anyone currently using {{ .stack }}.

@daidokoro
Copy link
Owner

daidokoro commented Jun 15, 2017

Ye, you're right, this will be a breaking change, but i'm still in beta, so no better time to do it :-)

The main reason I added {{ .stack }} was for the exact functionality you've added, so i'm more keen on going with your solution here, as it's a bit cleaner than an if-block and scales better.

Currently working on 0.60-beta, hopefully get it out later tonight, so i'll implement another keyword, possibly, {{ .stack_name }} to replace {{ .stack }}.

Thanks again Matt 👍

@daidokoro daidokoro merged commit 0a195c6 into daidokoro:master Jun 15, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants