Created
August 14, 2018 21:15
-
-
Save pbzona/dd8dc3b5f73d55f2cc2631cc0558489f to your computer and use it in GitHub Desktop.
Organize list of resources in cfn template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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