UNPKG

cloud-report

Version:

Collects and analyzes cloud resources

53 lines (52 loc) 2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../../../types"); const utils_1 = require("../../../utils"); const base_1 = require("../../base"); class EC2InstanceTerminationProtectionAnalyzer extends base_1.BaseAnalyzer { analyze(params, fullReport) { const allTerminationProtectionStatuses = params.termination_protection; const allInstances = params.instances; if (!allTerminationProtectionStatuses || !allInstances) { return undefined; } const termination_protection_enabled = { type: types_1.CheckAnalysisType.Reliability }; termination_protection_enabled.what = "Are there any instances without termination protection?"; termination_protection_enabled.why = `Instances can be accidentally terminated and data can be lost when they are without termination protection`; termination_protection_enabled.recommendation = `Recommended to enable termination protection for all production critical instances`; termination_protection_enabled.benchmark = ['all']; const allRegionsAnalysis = {}; for (const region in allInstances) { const regionInstances = allInstances[region]; allRegionsAnalysis[region] = []; for (const instance of regionInstances) { const instanceAnalysis = {}; instanceAnalysis.resource = { instanceId: instance.InstanceId, instanceName: utils_1.ResourceUtil.getNameByTags(instance), termination_protection: allTerminationProtectionStatuses[region][instance.InstanceId], }; instanceAnalysis.resourceSummary = { name: "Instance", value: `${instanceAnalysis.resource.instanceName} | ${instance.InstanceId}`, }; if (allTerminationProtectionStatuses[region][instance.InstanceId] && allTerminationProtectionStatuses[region][instance.InstanceId].Value) { instanceAnalysis.severity = types_1.SeverityStatus.Good; instanceAnalysis.message = "Already enabled"; } else { instanceAnalysis.severity = types_1.SeverityStatus.Warning; instanceAnalysis.message = "Not enabled"; instanceAnalysis.action = "Enable termination protection"; } allRegionsAnalysis[region].push(instanceAnalysis); } } termination_protection_enabled.regions = allRegionsAnalysis; return { termination_protection_enabled }; } } exports.EC2InstanceTerminationProtectionAnalyzer = EC2InstanceTerminationProtectionAnalyzer;