Repository: remind101/stacker
Pull request #193 (2016-08-08 18:42:05)

Handle existing stacks with no parameters
Also fixed a couple typos in comments. 

Related to #187


Patch:
diff --git a/stacker/actions/build.py b/stacker/actions/build.py
index 3381e69..fcebe46 100644
--- a/stacker/actions/build.py
+++ b/stacker/actions/build.py
@@ -246,7 +246,7 @@ class Action(BaseAction):
 
         """
         missing_params = list(set(required_params) - set(params.keys()))
-        if existing_stack:
+        if existing_stack and 'Parameters' in existing_stack:
             stack_params = {p['ParameterKey']: p['ParameterValue'] for p in existing_stack['Parameters']}
             for p in missing_params:
                 if p in stack_params:
diff --git a/stacker/providers/aws/default.py b/stacker/providers/aws/default.py
index a5c2e82..482565b 100644
--- a/stacker/providers/aws/default.py
+++ b/stacker/providers/aws/default.py
@@ -257,7 +257,8 @@ class Provider(BaseProvider):
 
         stack = stacks['Stacks'][0]
         parameters = dict()
-        for p in stack['Parameters']:
-            parameters[p['ParameterKey']] = p['ParameterValue']
+        if 'Parameters' in stack:
+            for p in stack['Parameters']:
+                parameters[p['ParameterKey']] = p['ParameterValue']
 
         return [json.dumps(template), parameters]
diff --git a/stacker/stack.py b/stacker/stack.py
index ea59a41..1c3fc3f 100644
--- a/stacker/stack.py
+++ b/stacker/stack.py
@@ -6,7 +6,7 @@ from . import util
 def _gather_parameters(stack_def, context_parameters):
     """Merges builder provided & stack defined parameters.
 
-    Ensures that more specificly defined parameters (ie: parameters defined
+    Ensures that more specifically defined parameters (ie: parameters defined
     specifically for the given stack: stack_name::parameter) override less
     specific parameters provided by the builder.
 
@@ -80,7 +80,7 @@ class Stack(object):
     def requires(self):
         requires = set([self.context.get_fqn(r) for r in
                         self.definition.get("requires", [])])
-        # Auto add dependencies when parameters reference the Ouptuts of
+        # Auto add dependencies when parameters reference the Outputs of
         # another stack.
         for value in self.parameters.values():
             stack_names = []


Test patch:
diff --git a/stacker/tests/actions/test_build.py b/stacker/tests/actions/test_build.py
index 5aa09eb..3744c46 100644
--- a/stacker/tests/actions/test_build.py
+++ b/stacker/tests/actions/test_build.py
@@ -66,6 +66,14 @@ class TestBuildAction(unittest.TestCase):
             self.build_action._resolve_parameters(parameters,
                                                   mock_blueprint)
 
+    def test_handle_missing_params(self):
+        stack = {'StackName': 'teststack'}
+        def_params = {"Address": "192.168.0.1"}
+        required = ["Address"]
+        result = self.build_action._handle_missing_parameters(def_params,
+                                                              required, stack)
+        self.assertEqual(result, def_params.items())
+
     def test_gather_missing_from_stack(self):
         stack_params = {"Address": "10.0.0.1"}
         stack = mock_stack(stack_params)