Skip to content

Commit

Permalink
support mixed parameters referencing / not referencing other stacks
Browse files Browse the repository at this point in the history
Currently parameters can reference multiple outputs in other stacks:
```
SomeParameter: stack1::Output1,stack2::Output2
```

This commit allows parameter lists to also include variables not
referencing another stack, e.g.:
```
SomeParameter: ${ThingInEnvFile},stack1::Output1
```

Behind the scenese, now values will always split on commas,
eliminating one of the nested conditionals.

Also changed 2 of the `if`s to `elif`s; probably won't make any
performance impact, but since each condition is independent it feels
more precise to me.
  • Loading branch information
troyready committed Aug 22, 2016
1 parent c76ac4b commit 99d810d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
37 changes: 22 additions & 15 deletions stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ def resolve_parameters(parameters, blueprint, context, provider):
blueprint.name, k)
continue
value = v
if isinstance(value, basestring) and "::" in value:
# Get from the Output(s) of another stack(s) in the stack_map
v_list = []
# v_list holds each value in the (potentially) comma-delimited list of
# values for each parameter
v_list = []
if isinstance(value, basestring):
values = value.split(",")
for v in values:
else:
values = [value]
for v in values:
if isinstance(v, basestring) and "::" in v:
# Get from the Output(s) of another stack(s) in the stack_map
v = v.strip()
stack_name, output = v.split("::")
stack_fqn = context.get_fqn(stack_name)
Expand All @@ -96,17 +101,19 @@ def resolve_parameters(parameters, blueprint, context, provider):
provider.get_output(stack_fqn, output))
except KeyError:
raise exceptions.OutputDoesNotExist(stack_fqn, v)
value = ",".join(v_list)
if value is None:
logger.debug("Got None value for parameter %s, not submitting it "
"to cloudformation, default value should be used.",
k)
continue
if isinstance(value, bool):
logger.debug("Converting parameter %s boolean \"%s\" to string.",
k, value)
value = str(value).lower()
params[k] = value
elif value is None:
logger.debug("Got None value for parameter %s, not submitting "
"it to cloudformation, default value should be "
"used.", k)
continue
elif isinstance(value, bool):
logger.debug("Converting parameter %s boolean \"%s\" to "
"string.", k, value)
v_list.append(str(value).lower())
else:
v_list.append(value)
if v_list != []:
params[k] = ",".join(v_list)
return params


Expand Down
3 changes: 3 additions & 0 deletions stacker/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def requires(self):
# support for list of Outputs
values = value.split(",")
for x in values:
# Skip parameters not referencing another stack
if '::' not in x:
continue
stack_name, _ = x.split("::")
stack_names.append(stack_name)
else:
Expand Down

0 comments on commit 99d810d

Please sign in to comment.