Beispiel #1
0
    def _construct_stack(self, rel_path, stack_group_config=None):
        """
        Constructs an individual Stack object from a config path and a
        base config.

        :param rel_path: A relative config file path.
        :type rel_path: str
        :param stack_group_config: The Stack group config to use as defaults.
        :type stack_group_config: dict
        :returns: Stack object
        :rtype: sceptre.stack.Stack
        """

        directory, filename = path.split(rel_path)
        if filename == self.context.config_file:
            pass

        self.templating_vars["stack_group_config"] = stack_group_config
        parsed_stack_group_config = self._parsed_stack_group_config(
            stack_group_config)
        config = self.read(rel_path, stack_group_config)
        stack_name = path.splitext(rel_path)[0]

        # Check for missing mandatory attributes
        for required_key in REQUIRED_KEYS:
            if required_key not in config:
                raise InvalidConfigFileError(
                    "Required attribute '{0}' not found in configuration of '{1}'."
                    .format(required_key, stack_name))

        abs_template_path = path.join(self.context.project_path,
                                      self.context.templates_path,
                                      sceptreise_path(config["template_path"]))

        s3_details = self._collect_s3_details(stack_name, config)
        stack = Stack(name=stack_name,
                      project_code=config["project_code"],
                      template_path=abs_template_path,
                      region=config["region"],
                      template_bucket_name=config.get("template_bucket_name"),
                      template_key_prefix=config.get("template_key_prefix"),
                      required_version=config.get("required_version"),
                      iam_role=config.get("iam_role"),
                      profile=config.get("profile"),
                      parameters=config.get("parameters", {}),
                      sceptre_user_data=config.get("sceptre_user_data", {}),
                      hooks=config.get("hooks", {}),
                      s3_details=s3_details,
                      dependencies=config.get("dependencies", []),
                      role_arn=config.get("role_arn"),
                      protected=config.get("protect", False),
                      tags=config.get("stack_tags", {}),
                      external_name=config.get("stack_name"),
                      notifications=config.get("notifications"),
                      on_failure=config.get("on_failure"),
                      stack_timeout=config.get("stack_timeout", 0),
                      stack_group_config=parsed_stack_group_config)

        del self.templating_vars["stack_group_config"]
        return stack
Beispiel #2
0
    def __init__(
        self, name, project_code, region, template_path=None, template_handler_config=None,
        template_bucket_name=None, template_key_prefix=None, required_version=None,
        parameters=None, sceptre_user_data=None, hooks=None, s3_details=None,
        iam_role=None, dependencies=None, role_arn=None, protected=False, tags=None,
        external_name=None, notifications=None, on_failure=None, profile=None,
        stack_timeout=0, stack_group_config={}
    ):
        self.logger = logging.getLogger(__name__)

        if template_path and template_handler_config:
            raise InvalidConfigFileError("Both 'template_path' and 'template' are set, specify one or the other")

        if not template_path and not template_handler_config:
            raise InvalidConfigFileError("Neither 'template_path' nor 'template' is set")

        self.name = sceptreise_path(name)
        self.project_code = project_code
        self.region = region
        self.template_bucket_name = template_bucket_name
        self.template_key_prefix = template_key_prefix
        self.required_version = required_version
        self.external_name = external_name or get_external_stack_name(self.project_code, self.name)
        self.template_path = template_path
        self.template_handler_config = template_handler_config
        self.s3_details = s3_details
        self._template = None
        self._connection_manager = None

        self.protected = protected
        self.role_arn = role_arn
        self.on_failure = on_failure
        self.dependencies = dependencies or []
        self.tags = tags or {}
        self.stack_timeout = stack_timeout
        self.iam_role = iam_role
        self.profile = profile
        self.hooks = hooks or {}
        self.parameters = parameters or {}
        self._sceptre_user_data = sceptre_user_data or {}
        self._sceptre_user_data_is_resolved = False
        self.notifications = notifications or []
        self.stack_group_config = stack_group_config or {}