Closed z0mbix closed 7 years ago
Hi @z0mbix , there's currently not any way to do that. What's the motivation? Would you like to keep the stack name in source control?
I'm interesting in doing this as well, for exactly the reason you mentioned (alongside chosen parameter values for the stack) -- it'd be nice to have a representation of the deployed infrastructure in revision control.
Would you be open to a pull request along those lines? Thus far I've experimented with a quick hack, and have the ARGV options (e.g. stack name) check for global variables as well, e.g.,
$stack_name = "myfancy_stack"
template do
value AWSTemplateFormatVersion: '2010-09-09'
value Description: 'blah'
...
end.exec!
I'd obviously be open to doing it more correctly though (variables passed around the methods? moving the standalone methods to a class that could share the variables?).
Tried the ARGV way for a while, but now I'm trying to make all the stacks available as library calls which makes ARGV a non thread-safe option. So far, I ended up monkey-patching TemplateDSL:
class TemplateDSL
def name(stack_name)
@stack_name = stack_name
end
end
Adding stack_name as attr_accessor (it's already defined as attr_reader) doesn't make instance_eval happy, hence the explicit setter with a different name. The templates now read something like:
template do
name 'foo'
value AWSTemplateFormatVersion: '2010-09-09'
# ...
end
I like the format of the resulting template from your example, @SaltwaterC . I think I'd rather see if we can swap to an attr_accessor
in the actual implementation, but I like where this is headed.
I went the setter way because attr_* doesn't play nice with instance_eval.
@SaltwaterC I like this, and it doesn't feel like it would break anything too hard. Can I encourage you to turn this monkey-patch into a pull request, instead?
Turns out this entirely unnecessary: you can just manually set using:
template do
@stack_name = 'foo'
[...]
end
and it works fine without any code changes.
Hi,
Is there any way to set the stack name in the ruby template instead of having to use --stack-name each time?
Thanks