Last active
April 9, 2025 18:46
-
-
Save BigBlueHat/6a233fecc179ba149a136449aaadd4a3 to your computer and use it in GitHub Desktop.
Generate `gcp.spc` from `gcloud projects list --format=json`
This file contains hidden or 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
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