Skip to content

Commit

Permalink
allow configs without stacks (cloudtools#640)
Browse files Browse the repository at this point in the history
* allow configs without stacks

This relaxes the current stack validation, replacing it instead with
action warning messages.

With this, configurations can be created with only hooks.

* update functional test

* Fix tests

* Fix output for warning when no stacks detected

* No longer throw error when configs missing stacks
  • Loading branch information
phobologic authored Aug 5, 2018
1 parent 47d7525 commit 103e143
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ def run(self, concurrency=0, outline=False,
"""
plan = self._generate_plan(tail=tail)
if not plan.keys():
logger.warn('WARNING: No stacks detected (error in config?)')
if not outline and not dump:
plan.outline(logging.DEBUG)
logger.debug("Launching stacks: %s", ", ".join(plan.keys()))
Expand Down
2 changes: 2 additions & 0 deletions stacker/actions/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def pre_run(self, outline=False, *args, **kwargs):

def run(self, force, concurrency=0, tail=False, *args, **kwargs):
plan = self._generate_plan(tail=tail)
if not plan.keys():
logger.warn('WARNING: No stacks detected (error in config?)')
if force:
# need to generate a new plan to log since the outline sets the
# steps to COMPLETE in order to log them
Expand Down
5 changes: 4 additions & 1 deletion stacker/actions/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ def _generate_plan(self):
def run(self, concurrency=0, *args, **kwargs):
plan = self._generate_plan()
plan.outline(logging.DEBUG)
logger.info("Diffing stacks: %s", ", ".join(plan.keys()))
if plan.keys():
logger.info("Diffing stacks: %s", ", ".join(plan.keys()))
else:
logger.warn('WARNING: No stacks detected (error in config?)')
walker = build_walker(concurrency)
plan.execute(walker)

Expand Down
2 changes: 2 additions & 0 deletions stacker/actions/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Action(BaseAction):

def run(self, *args, **kwargs):
logger.info('Outputs for stacks: %s', self.context.get_fqn())
if not self.context.get_stacks():
logger.warn('WARNING: No stacks detected (error in config?)')
for stack in self.context.get_stacks():
provider = self.build_provider(stack)

Expand Down
2 changes: 1 addition & 1 deletion stacker/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class Config(Model):
lookups = DictType(StringType, serialize_when_none=False)

stacks = ListType(
ModelType(Stack), default=[], validators=[not_empty_list])
ModelType(Stack), default=[])

def _remove_excess_keys(self, data):
excess_keys = set(data.keys())
Expand Down
10 changes: 0 additions & 10 deletions stacker/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ def test_config_validate_stack_class_and_template_paths(self):
stack_errors['class_path'][0].__str__(),
"template_path cannot be present when class_path is provided.")

def test_config_validate_no_stacks(self):
config = Config({"namespace": "prod"})
with self.assertRaises(exceptions.InvalidConfig) as ex:
config.validate()

error = ex.exception.errors['stacks'].errors[0]
self.assertEquals(
error.__str__(),
"Should have more than one element.")

def test_config_validate_missing_name(self):
config = Config({
"namespace": "prod",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_suite/02_stacker_build_empty_config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ load ../test_helper
@test "stacker build - empty config" {
stacker build <(echo "")
assert ! "$status" -eq 0
assert_has_line 'Should have more than one element'
assert_has_line 'stacker.exceptions.InvalidConfig:'
}
6 changes: 4 additions & 2 deletions tests/test_suite/03_stacker_build-config_with_no_stacks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
load ../test_helper

@test "stacker build - config with no stacks" {
needs_aws

stacker build - <<EOF
namespace: ${STACKER_NAMESPACE}
EOF
assert ! "$status" -eq 0
assert_has_line 'Should have more than one element'
assert "$status" -eq 0
assert_has_line 'WARNING: No stacks detected (error in config?)'
}

0 comments on commit 103e143

Please sign in to comment.