From 7b309ca05d5b1a219464c774794b6cdfa7c449d1 Mon Sep 17 00:00:00 2001 From: Khai Do <3697686+zaro0508@users.noreply.github.com> Date: Fri, 15 Oct 2021 14:30:55 -0700 Subject: [PATCH] Set file as the default template handler type (#1127) Now that we have template handlers we want to encourage users to migrate from using `template_path` to `template` in their Sceptre stack config files. To make that transition easier we set the default `template` type to 'file' which will save the user from having to specify a full `template` block if they just want to load a file from disk --- docs/_source/docs/template_handlers.rst | 3 ++- sceptre/template.py | 2 ++ tests/test_template.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/_source/docs/template_handlers.rst b/docs/_source/docs/template_handlers.rst index 9efc402a1..d7192614c 100644 --- a/docs/_source/docs/template_handlers.rst +++ b/docs/_source/docs/template_handlers.rst @@ -28,6 +28,8 @@ file Loads a template from disk. Supports JSON, YAML, Jinja2 and Python files. Will be used if the ``template_path`` Stack config property is set, for backwards compatibility reasons. +This is the default template handler type, setting the ``file`` type is option. + Syntax: .. code-block:: yaml @@ -41,7 +43,6 @@ Example: .. code-block:: yaml template: - type: file path: storage/bucket.yaml s3 diff --git a/sceptre/template.py b/sceptre/template.py index c8a7af65d..de6779069 100644 --- a/sceptre/template.py +++ b/sceptre/template.py @@ -56,6 +56,8 @@ def __init__( self.name = name self.handler_config = handler_config + if self.handler_config is not None and self.handler_config.get('type') is None: + self.handler_config['type'] = 'file' self.sceptre_user_data = sceptre_user_data self.stack_group_config = stack_group_config self.connection_manager = connection_manager diff --git a/tests/test_template.py b/tests/test_template.py index fd56c0fd3..327ebafec 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -48,6 +48,17 @@ def setup_method(self, test_method): connection_manager=connection_manager, ) + def test_initialise_template_default_handler_type(self): + template = Template( + name="template_name", + handler_config={"path": "/folder/template.py"}, + sceptre_user_data={}, + stack_group_config={}, + connection_manager={}, + ) + + assert template.handler_config == {"type": "file", "path": "/folder/template.py"} + def test_initialise_template(self): assert self.template.handler_config == {"type": "file", "path": "/folder/template.py"} assert self.template.name == "template_name"