def pre_terraform_destroy(self): """ Remove all targets from the coudwatch rules before starting destroy. This is required as it would be possible to delete and re create cloudwatch rules and then attach targets in the PacBot application. So terraform cannot track them and fail to execute destroy. """ for rule in get_rule_engine_cloudwatch_rules_var(): rule_name = rule['ruleId'] try: cloudwatch_event.remove_all_targets_of_a_rule( rule_name, Settings.AWS_AUTH_CRED) except Exception as e: message = "\n\t ** Not able to remove targets from the rule: %s: Reason: %s **\n" % (rule_name, str(e)) print(MsgMixin.BERROR_ANSI + message + MsgMixin.RESET_ANSI) sys.exit()
def check_exists_before(self, input, tf_outputs): exists = False checked_details = {} if not self.resource_in_tf_output(tf_outputs): for rule in get_rule_engine_cloudwatch_rules_var(): rule_name = rule['ruleId'] exists = cloudwatch_event.check_rule_exists( rule_name, input.aws_access_key, input.aws_secret_key, input.aws_region) if exists: checked_details = {'attr': "name", 'value': rule_name} break return exists, checked_details
def check_exists_before(self, input, tf_outputs): """ This method overrides the base class method, since here we need to check the existennce of a list of CW rules """ exists = False checked_details = {} if not self.resource_in_tf_output(tf_outputs): for rule in get_rule_engine_cloudwatch_rules_var(): rule_name = rule['ruleId'] exists = cloudwatch_event.check_rule_exists( rule_name, input.AWS_AUTH_CRED) if exists: checked_details = {'attr': "name", 'value': rule_name} break return exists, checked_details
class RulesListVariable(TerraformVariable): variable_name = "rules" variable_type = "list" default_value = [] variable_dict_input = get_rule_engine_cloudwatch_rules_var()