I would like realized inventory of GCP API which are enabled in my organization, so I want to use bash script in my cloud shell terminal.
The code below works, but when I also want to organize result in array (with column Project and API), it doesn't work.
For example, when I put gcloud command in a bash variable, it doesn't work:
services=gcloud services list --enabled --project $project
#!/bin/bash
for project in $(gcloud projects list --format="value(projectId)")
do
echo "ProjectId: $project"
gcloud services list --enabled --project $project
done
I have a solution with an additional nested loop
#!/bin/bash
for project in $(gcloud projects list --format="value(projectId)")
do
for api in $(gcloud services list --enabled --project $project --format='value(NAME)')
do
echo "${project},${api}"
done
done
It's a CSV format, it should be easy to read it with Excel afterward.