Skip to content

Commit

Permalink
[Resolve Sceptre#1334] Add a dump vars command
Browse files Browse the repository at this point in the history
The dump vars command dumps the compiled templating_vars for the purpose
of additional debugging information.
  • Loading branch information
alexharv074 committed Apr 23, 2023
1 parent d96389d commit d2ce186
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sceptre/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,36 @@ def dump_config(ctx, path):
else:
for config in output:
write(config, output_format)


@dump_group.command(name="vars")
@click.argument("path")
@click.pass_context
@catch_exceptions
def dump_config(ctx, path):
"""
Dump the template vars.
\f
:param path: Path to execute the command on or path to stack group
"""
context = SceptreContext(
command_path=path,
command_params=ctx.params,
project_path=ctx.obj.get("project_path"),
user_variables=ctx.obj.get("user_variables"),
output_format=ctx.obj.get("output_format"),
options=ctx.obj.get("options"),
ignore_dependencies=ctx.obj.get("ignore_dependencies"),
)
plan = SceptrePlan(context)
responses = plan.dump_vars()

output = []
for stack, vars in responses.items():
output.append({stack.external_name: vars})

output_format = "json" if context.output_format == "json" else "yaml"

for vars in output:
write(vars, output_format)
1 change: 1 addition & 0 deletions sceptre/config/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ def _construct_stack(self, rel_path, stack_group_config=None):
obsolete=config.get("obsolete", False),
stack_group_config=parsed_stack_group_config,
config=config,
vars=self.templating_vars,
)

del self.templating_vars["stack_group_config"]
Expand Down
7 changes: 7 additions & 0 deletions sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,3 +1150,10 @@ def dump_config(self):
Dump the config for a stack.
"""
return self.stack.config

@add_stack_hooks
def dump_vars(self):
"""
Dump the vars for a stack.
"""
return self.stack.vars
7 changes: 7 additions & 0 deletions sceptre/plan/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,10 @@ def dump_config(self, *args):
"""
self.resolve(command=self.dump_config.__name__)
return self._execute(*args)

def dump_vars(self, *args):
"""
Dump the vars for a stack.
"""
self.resolve(command=self.dump_vars.__name__)
return self._execute(*args)
6 changes: 6 additions & 0 deletions sceptre/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class Stack:
If not supplied, Sceptre uses default value (3600 seconds)
:param stack_group_config: The StackGroup config for the Stack
:param config: The complete config for the stack. Used by dump config.
:param vars: The complete templating vars for the Stack. Used by dump vars.
"""

parameters = ResolvableContainerProperty("parameters")
Expand Down Expand Up @@ -195,6 +199,7 @@ def __init__(
obsolete=False,
stack_group_config: dict = {},
config: dict = {},
vars: dict = {},
):
self.logger = logging.getLogger(__name__)

Expand All @@ -213,6 +218,7 @@ def __init__(
)
self.stack_group_config = stack_group_config or {}
self.config = config or {}
self.vars = vars or {}
self.stack_timeout = stack_timeout
self.profile = profile
self.template_key_prefix = template_key_prefix
Expand Down

0 comments on commit d2ce186

Please sign in to comment.