diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index b58d1dcf0..824d568a2 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from datetime import datetime import json +import yaml import uuid import boto.cloudformation @@ -17,7 +18,7 @@ class FakeStack(BaseModel): self.stack_id = stack_id self.name = name self.template = template - self.template_dict = json.loads(self.template) + self._parse_template() self.parameters = parameters self.region_name = region_name self.notification_arns = notification_arns if notification_arns else [] @@ -70,6 +71,12 @@ class FakeStack(BaseModel): resource_properties=resource_properties, )) + def _parse_template(self): + try: + self.template_dict = json.loads(self.template) + except json.JSONDecodeError: + self.template_dict = yaml.load(self.template) + @property def stack_parameters(self): return self.resource_map.resolved_parameters diff --git a/tests/test_cloudformation/test_stack_parsing.py b/tests/test_cloudformation/test_stack_parsing.py index c2af6363a..610b02325 100644 --- a/tests/test_cloudformation/test_stack_parsing.py +++ b/tests/test_cloudformation/test_stack_parsing.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import json +import yaml from mock import patch import sure # noqa @@ -126,6 +127,20 @@ def test_parse_stack_with_name_type_resource(): queue.should.be.a(Queue) +def test_parse_stack_with_yaml_template(): + stack = FakeStack( + stack_id="test_id", + name="test_stack", + template=yaml.dump(name_type_template), + parameters={}, + region_name='us-west-1') + + stack.resource_map.should.have.length_of(1) + list(stack.resource_map.keys())[0].should.equal('Queue') + queue = list(stack.resource_map.values())[0] + queue.should.be.a(Queue) + + def test_parse_stack_with_outputs(): stack = FakeStack( stack_id="test_id",