Skip to content

Commit

Permalink
Add add_output helper method on Blueprints (#611)
Browse files Browse the repository at this point in the history
Got sick of constantly typing `Output("Blah", Value="foo")` and figured
we could make this easier.
  • Loading branch information
phobologic committed Jun 25, 2018
1 parent 45b122f commit 6e29488
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion stacker/blueprints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from stacker.variables import Variable

from troposphere import (
Output,
Parameter,
Ref,
Template
Template,
)

from ..exceptions import (
Expand Down Expand Up @@ -522,6 +523,15 @@ def set_template_description(self, description):
"""
self.template.add_description(description)

def add_output(self, name, value):
"""Simple helper for adding outputs.
Args:
name (str): The name of the output to create.
value (str): The value to put in the output.
"""
self.template.add_output(Output(name, Value=value))

@property
def requires_change_set(self):
"""Returns true if the underlying template has transforms."""
Expand Down
19 changes: 19 additions & 0 deletions stacker/tests/blueprints/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ def create_template(self):
)


class TestBaseBlueprint(unittest.TestCase):
def test_add_output(self):
output_name = "MyOutput1"
output_value = "OutputValue"

class TestBlueprint(Blueprint):
VARIABLES = {}

def create_template(self):
self.template.add_version('2010-09-09')
self.template.add_description('TestBlueprint')
self.add_output(output_name, output_value)

bp = TestBlueprint(name="test", context=mock_context())
bp.render_template()
self.assertEqual(bp.template.outputs[output_name].properties["Value"],
output_value)


class TestVariables(unittest.TestCase):

def test_defined_variables(self):
Expand Down

0 comments on commit 6e29488

Please sign in to comment.