How to use the taskcat._cfn.template.Template function in taskcat

To help you get started, we’ve selected a few taskcat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-quickstart / taskcat / taskcat / _config.py View on Github external
def get_templates(self, project_root: Path):
        templates = {}
        for test_name, test in self.config.tests.items():
            templates[test_name] = Template(
                template_path=project_root / test.template,
                project_root=project_root,
                s3_key_prefix=f"{self.config.project.name}/",
            )
        return templates
github aws-quickstart / taskcat / taskcat / _cfn / stack.py View on Github external
def create(
        cls,
        region: TestRegion,
        stack_name: str,
        template: Template,
        tags: List[Tag] = None,
        disable_rollback: bool = True,
        test_name: str = "",
        uuid: UUID = None,
    ) -> "Stack":
        parameters = cls._cfn_format_parameters(region.parameters)
        uuid = uuid if uuid else uuid4()
        cfn_client = region.client("cloudformation")
        tags = [t.dump() for t in tags] if tags else []
        template = Template(
            template_path=template.template_path,
            project_root=template.project_root,
            s3_key_prefix=template.s3_key_prefix,
            url=s3_url_maker(
                region.s3_bucket.name, template.s3_key, region.client("s3")
            ),
        )
        stack_id = cfn_client.create_stack(
            StackName=stack_name,
            TemplateURL=template.url,
            Parameters=parameters,
            DisableRollback=disable_rollback,
            Tags=tags,
            Capabilities=Capabilities.ALL,
        )["StackId"]
        stack = cls(region, stack_id, template, test_name, uuid)
github aws-quickstart / taskcat / taskcat / _cfn / template.py View on Github external
for resource in self.template["Resources"].keys():
            resource = self.template["Resources"][resource]
            if resource["Type"] == "AWS::CloudFormation::Stack":
                child_name = self._template_url_to_path(
                    resource["Properties"]["TemplateURL"]
                )
                if child_name:
                    children.add(child_name)
        for child in children:
            child_template_instance = None
            for descendent in self.descendents:
                if str(descendent.template_path) == str(child):
                    child_template_instance = descendent
            if not child_template_instance:
                try:
                    child_template_instance = Template(
                        child,
                        self.project_root,
                        self._get_relative_url(child),
                        self._s3_key_prefix,
                    )
                except Exception:  # pylint: disable=broad-except
                    LOG.debug("Traceback:", exc_info=True)
                    LOG.error(f"Failed to add child template {child}")
            if isinstance(child_template_instance, Template):
                self.children.append(child_template_instance)
github aws-quickstart / taskcat / taskcat / _config.py View on Github external
def get_templates(self, project_root: Path):
        templates = {}
        for test_name, test in self.config.tests.items():
            templates[test_name] = Template(
                template_path=project_root / test.template,
                project_root=project_root,
                s3_key_prefix=f"{self.config.project.name}/",
            )
        return templates
github aws-quickstart / taskcat / taskcat / _cfn / stack.py View on Github external
)
                    + ".template"
                )
                absolute_path = path / fname
                template_str = ordered_dump(tempate_body, dumper=yaml.SafeDumper)
                if not absolute_path.exists():
                    with open(absolute_path, "w") as fh:
                        fh.write(template_str)
            except Exception as e:  # pylint: disable=broad-except
                LOG.warning(
                    f"Failed to attach child stack "
                    f'{stack_properties["StackId"]} {str(e)}'
                )
                LOG.debug("traceback", exc_info=True)
                return None
        template = Template(
            template_path=str(absolute_path),
            project_root=parent_stack.template.project_root,
            url=url,
        )
        stack = cls(
            parent_stack.region,
            stack_properties["StackId"],
            template,
            parent_stack.name,
            parent_stack.uuid,
        )
        stack.set_stack_properties(stack_properties)
        return stack
github aws-quickstart / taskcat / taskcat / _config.py View on Github external
    @staticmethod
    def _dict_from_template(file_path: Path) -> dict:
        relative_path = str(file_path.relative_to(PROJECT_ROOT))
        config_dict = (
            BaseConfig()
            .from_dict(
                {"project": {"template": relative_path}, "tests": {"default": {}}}
            )
            .to_dict()
        )
        if not file_path.is_file():
            raise TaskCatException(f"invalid template path {file_path}")
        try:
            template = Template(str(file_path)).template
        except Exception as e:
            LOG.warning(f"failed to load template from {file_path}")
            LOG.debug(str(e), exc_info=True)
            raise e
        if not template.get("Metadata"):
            return config_dict
        if not template["Metadata"].get("taskcat"):
            return config_dict
        template_config_dict = template["Metadata"]["taskcat"]
        if not template_config_dict.get("project"):
            template_config_dict["project"] = {}
        template_config_dict["project"]["template"] = relative_path
        if not template_config_dict.get("tests"):
            template_config_dict["tests"] = {"default": {}}
        return template_config_dict