Skip to content

Instantly share code, notes, and snippets.

@BigBlueHat
Last active April 9, 2025 18:46
Show Gist options
  • Save BigBlueHat/6a233fecc179ba149a136449aaadd4a3 to your computer and use it in GitHub Desktop.
Save BigBlueHat/6a233fecc179ba149a136449aaadd4a3 to your computer and use it in GitHub Desktop.
Generate `gcp.spc` from `gcloud projects list --format=json`
import fs from 'node:fs';
// generate this file using...
// `gcloud projects list --format=json > gcp-projects-list.json`
const data = fs.readFileSync('gcp-projects-list.json', 'utf8');
const jsonData = JSON.parse(data);
let output = `connection "gcp" {
plugin = "gcp"
type = "aggregator"
connections = ["gcp_project_*"]
}
`;
// loop over project names and make compatiable SPC entries
const projects = jsonData.map((project) => {
return {
id: project.projectId,
underscored: project.projectId.replaceAll('-', '_')
};
});
projects.forEach(project => {
const addition = `
connection "gcp_project_${project.underscored}" {
plugin = "gcp"
project = "${project.id}"
ignore_error_messages = ["^.*API has not been used.*$"]
}\n`;
output = output.concat(addition);
});
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment