def stack_set_state_machine_input_v1(self, resource, account_list) -> dict:

        local_file = StageFile(self.logger, resource.template_file)
        template_url = local_file.get_staged_file()

        # set region variables
        if len(resource.regions) > 0:
            region = resource.regions[0]
            region_list = resource.regions
        else:
            region = self.region
            region_list = [region]

        # if parameter file link is provided for the CFN resource

        parameters = self._load_params_from_file(resource.parameter_file)

        sm_params = self.param_handler.update_params(parameters, account_list,
                                                     region, False)

        ssm_parameters = self._create_ssm_input_map(resource.ssm_parameters)

        # generate state machine input list
        stack_set_name = "CustomControlTower-{}".format(resource.name)
        resource_properties = StackSetResourceProperties(
            stack_set_name, template_url, sm_params,
            os.environ.get('CAPABILITIES'), account_list, region_list,
            ssm_parameters)
        ss_input = InputBuilder(resource_properties.get_stack_set_input_map())
        return ss_input.input_map()
    def parse_scp_manifest(self) -> list:
        self.logger.info("Processing SCPs from {} file".format(
            os.environ.get('MANIFEST_FILE_PATH')))
        state_machine_inputs = []

        for policy in self.manifest.organization_policies:
            # Generate the list of OUs to attach this SCP to
            ou_list = []
            attach_ou_list = set(policy.apply_to_accounts_in_ou)

            for ou in attach_ou_list:
                ou_list.append((ou, 'Attach'))

            local_file = StageFile(self.logger, policy.policy_file)
            policy_url = local_file.stage_file()
            resource_properties = SCPResourceProperties(
                policy.name, policy.description, policy_url, ou_list)
            scp_input = InputBuilder(resource_properties.get_scp_input_map())
            sm_input = scp_input.input_map()
            self.logger.debug(sm_input)
            state_machine_inputs.append(sm_input)

        # Exit if there are no organization policies
        if len(state_machine_inputs) == 0:
            self.logger.info("Organization policies not found"
                             " in the manifest.")
            sys.exit(0)
        else:
            return state_machine_inputs
示例#3
0
def build_scp_input():
    # get SCP output
    resource_properties = SCPResourceProperties(name, description, policy_url,
                                                policy_list, account_id,
                                                operation, ou_list, delimiter)
    scp_input = InputBuilder(resource_properties.get_scp_input_map())
    return scp_input.input_map()
示例#4
0
    def _get_state_machine_input(self, resource, account_list) -> dict:
        local_file = StageFile(self.logger, resource.template_file)
        template_url = local_file.get_staged_file()

        parameters = {}

        # set region variables
        if len(resource.regions) > 0:
            region = resource.regions[0]
            region_list = resource.regions
        else:
            region = self.manifest.region
            region_list = [region]

        # if parameter file link is provided for the CFN resource
        if resource.parameter_file:
            parameters = self._load_params(resource.parameter_file,
                                           account_list, region)

        ssm_parameters = self._create_ssm_input_map(resource.ssm_parameters)

        accounts = "" if resource.parameter_override == 'true' or account_list == [] else account_list
        regions = "" if resource.parameter_override == 'true' or account_list == [] else region_list

        # generate state machine input list
        stack_set_name = "AWS-Landing-Zone-Baseline-{}".format(resource.name)
        resource_properties = StackSetResourceProperties(
            stack_set_name, template_url, parameters,
            os.environ.get('CAPABILITIES'), accounts, regions, ssm_parameters)
        ss_input = InputBuilder(resource_properties.get_stack_set_input_map())
        return ss_input.input_map()
示例#5
0
def build_stack_set_input():
    # get stack set output
    resource_properties = StackSetResourceProperties(stack_set_name,
                                                     template_url, parameters,
                                                     capabilities,
                                                     account_list, region_list,
                                                     ssm_parameters)
    ss_input = InputBuilder(resource_properties.get_stack_set_input_map())
    return ss_input.input_map()
    def scp_sm_input(self, attach_ou_list, policy, policy_url) -> dict:
        ou_list = []

        for ou in attach_ou_list:
            ou_list.append((ou, 'Attach'))
        resource_properties = SCPResourceProperties(policy.name,
                                                    policy.description,
                                                    policy_url, ou_list)
        scp_input = InputBuilder(resource_properties.get_scp_input_map())
        sm_input = scp_input.input_map()
        self.logger.debug("&&&&& sm_input &&&&&&")
        self.logger.debug(sm_input)
        return sm_input
    def stack_set_state_machine_input_v2(self, resource, account_list) -> dict:

        local_file = StageFile(self.logger, resource.resource_file)
        template_url = local_file.get_staged_file()

        parameters = {}
        # set region variables
        if len(resource.regions) > 0:
            region = resource.regions[0]
            region_list = resource.regions
        else:
            region = self.region
            region_list = [region]

        # if parameter file link is provided for the CFN resource
        if resource.parameter_file == "":
            self.logger.info("parameter_file property not found in the "
                             "manifest")
            self.logger.info(resource.parameter_file)
            self.logger.info(resource.parameters)
            parameters = self._load_params_from_manifest(resource.parameters)
        elif not resource.parameters:
            self.logger.info("parameters property not found in the "
                             "manifest")
            self.logger.info(resource.parameter_file)
            self.logger.info(resource.parameters)
            parameters = self._load_params_from_file(resource.parameter_file)

        sm_params = self.param_handler.update_params(parameters, account_list,
                                                     region, False)

        self.logger.info(
            "Input Parameters for State Machine: {}".format(sm_params))

        ssm_parameters = self._create_ssm_input_map(resource.export_outputs)

        # generate state machine input list
        stack_set_name = "CustomControlTower-{}".format(resource.name)
        resource_properties = StackSetResourceProperties(
            stack_set_name, template_url, sm_params,
            os.environ.get('CAPABILITIES'), account_list, region_list,
            ssm_parameters)
        ss_input = InputBuilder(resource_properties.get_stack_set_input_map())
        return ss_input.input_map()