delfick / bespin

Opinionated wrapper around boto that reads yaml
MIT License
6 stars 8 forks source link

DynamicVariable.stack is always string #83

Closed atward closed 7 years ago

atward commented 7 years ago

I can't work out a situation where var.stack is ever not a string. https://github.com/delfick/bespin/blob/9789ec2dbf07b8af00ea4875f7e359b801a7a4c0/bespin/option_spec/stack_objs.py#L351 https://github.com/delfick/bespin/blob/9789ec2dbf07b8af00ea4875f7e359b801a7a4c0/bespin/option_spec/stack_objs.py#L439

I've gone through git history and it seems it's always been a string. @delfick, can you shed any light about this? How would you go about calling Stack.output_yet_to_be_deployed?

delfick commented 7 years ago

The stack part of the dynamic variable is formatted into the config, so if you say "{stacks.blah}" then it's gonna be the blah stack object. You can specify it as a string as the name of the stack so that you can refer to stacks that aren't in the configuration, or you can refer to the object itself so that you don't repeat it's stack name.

Seeing that it does that is a bit non obvious

https://github.com/delfick/bespin/blob/d9a93a853ba29446417f1222385cff1cf4f8867b/bespin/option_spec/stack_specs.py#L27 uses this monstrosity called the many_item_formatted_spec which basically says the value can be many items and they are all formatted.

So the options on the var_spec says that it has to have atleast one item which is either a string_or_int_as_string or a list of those. And then it has an optional_spec (i.e. the second item in the value is optional) and because we specify the formatter on var_spec, all the values are formatted.

The create_result method is given the items in the value in order followed by meta and the whole value and whatever dividers has (I forget).

The YYY_RESOLVED_BLAH_YYY thing is because a sanity check before you've deployed any of the stacks would otherwise fail because it can't get the output from a stack that doesn't exist yet.

atward commented 7 years ago

I get all that, but it's still a String Formatter. Is there special logic in option_merge if the entire string is a formatted value (eg: "{foo}" over say " {bar}"?

delfick commented 7 years ago

yeap, so if after tokenising the string, there's only one result https://github.com/delfick/option_merge/blob/master/option_merge/formatter.py#L200 then it's returned as is

and this logic here https://github.com/delfick/option_merge/blob/master/option_merge/formatter.py#L153 means it isn't turned into a string