Skip to content

Commit 103e143

Browse files
authored
allow configs without stacks (#640)
* 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
1 parent 47d7525 commit 103e143

8 files changed

Lines changed: 16 additions & 15 deletions

File tree

stacker/actions/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ def run(self, concurrency=0, outline=False,
413413
414414
"""
415415
plan = self._generate_plan(tail=tail)
416+
if not plan.keys():
417+
logger.warn('WARNING: No stacks detected (error in config?)')
416418
if not outline and not dump:
417419
plan.outline(logging.DEBUG)
418420
logger.debug("Launching stacks: %s", ", ".join(plan.keys()))

stacker/actions/destroy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def pre_run(self, outline=False, *args, **kwargs):
9090

9191
def run(self, force, concurrency=0, tail=False, *args, **kwargs):
9292
plan = self._generate_plan(tail=tail)
93+
if not plan.keys():
94+
logger.warn('WARNING: No stacks detected (error in config?)')
9395
if force:
9496
# need to generate a new plan to log since the outline sets the
9597
# steps to COMPLETE in order to log them

stacker/actions/diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ def _generate_plan(self):
278278
def run(self, concurrency=0, *args, **kwargs):
279279
plan = self._generate_plan()
280280
plan.outline(logging.DEBUG)
281-
logger.info("Diffing stacks: %s", ", ".join(plan.keys()))
281+
if plan.keys():
282+
logger.info("Diffing stacks: %s", ", ".join(plan.keys()))
283+
else:
284+
logger.warn('WARNING: No stacks detected (error in config?)')
282285
walker = build_walker(concurrency)
283286
plan.execute(walker)
284287

stacker/actions/info.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Action(BaseAction):
1818

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

stacker/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class Config(Model):
402402
lookups = DictType(StringType, serialize_when_none=False)
403403

404404
stacks = ListType(
405-
ModelType(Stack), default=[], validators=[not_empty_list])
405+
ModelType(Stack), default=[])
406406

407407
def _remove_excess_keys(self, data):
408408
excess_keys = set(data.keys())

stacker/tests/test_config.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ def test_config_validate_stack_class_and_template_paths(self):
9494
stack_errors['class_path'][0].__str__(),
9595
"template_path cannot be present when class_path is provided.")
9696

97-
def test_config_validate_no_stacks(self):
98-
config = Config({"namespace": "prod"})
99-
with self.assertRaises(exceptions.InvalidConfig) as ex:
100-
config.validate()
101-
102-
error = ex.exception.errors['stacks'].errors[0]
103-
self.assertEquals(
104-
error.__str__(),
105-
"Should have more than one element.")
106-
10797
def test_config_validate_missing_name(self):
10898
config = Config({
10999
"namespace": "prod",

tests/test_suite/02_stacker_build_empty_config.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ load ../test_helper
55
@test "stacker build - empty config" {
66
stacker build <(echo "")
77
assert ! "$status" -eq 0
8-
assert_has_line 'Should have more than one element'
8+
assert_has_line 'stacker.exceptions.InvalidConfig:'
99
}

tests/test_suite/03_stacker_build-config_with_no_stacks.bats

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
load ../test_helper
44

55
@test "stacker build - config with no stacks" {
6+
needs_aws
7+
68
stacker build - <<EOF
79
namespace: ${STACKER_NAMESPACE}
810
EOF
9-
assert ! "$status" -eq 0
10-
assert_has_line 'Should have more than one element'
11+
assert "$status" -eq 0
12+
assert_has_line 'WARNING: No stacks detected (error in config?)'
1113
}

0 commit comments

Comments
 (0)