Skip to content

Instantly share code, notes, and snippets.

@pbzona
Created August 14, 2018 21:15
Show Gist options
  • Save pbzona/dd8dc3b5f73d55f2cc2631cc0558489f to your computer and use it in GitHub Desktop.
Save pbzona/dd8dc3b5f73d55f2cc2631cc0558489f to your computer and use it in GitHub Desktop.
Organize list of resources in cfn template
const fs = require('fs');
// Change this line to your template
const templateFile = './example-template.json';
const cfn = JSON.parse(fs.readFileSync(templateFile));
const resources = cfn.Resources;
const keys = Object.keys(resources);
let obj = {};
for (resource in resources) {
const type = resources[resource]['Type'].split('::')[2];
if (obj.hasOwnProperty(type)) {
obj[type].push(resource);
} else {
obj[type] = [resource];
}
}
const outputFile = './report.txt';
fs.writeFileSync(outputFile, '');
const print = data => {
fs.appendFileSync(outputFile, `${data}\n`);
console.log(data);
};
for (item in obj) {
print(`${item}: ${obj[item].length}`);
obj[item].forEach(i => {
print(`\t${i}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment