1

Is there any command to list all the GCP project quota in a single excel file with only top headers. I tried to apply FOR loop on quota management however it gives me output with header included every time with new projects when appended.

gcloud compute project-info describe --flatten=quotas -- format='csv(quotas.metric,quotas.limit,quotas.usage)' will provide for one project. However require for all project on Org level and folder level in a single excel file.

Amit
  • 11
  • 3
  • There is no quota export at Org or folder level. It's per project. You have to build yourselves the script. – guillaume blaquiere Aug 18 '20 at 12:04
  • @guillaumeblaquiere Yes, hence asking for assistance if anyone had created the script. I am not able to achieve the same – Amit Aug 18 '20 at 13:58

1 Answers1

3

I crafted this bash code that can help you in order to iterate all projects related with the account used with GCloud feel free to modify this code according your use case

#!/bin/bash
#unique header
echo "ProjectId,Metric,Quota,Usage"
gcloud projects list --format="csv[no-heading](projectId,name)" |\
while IFS="," read -r ID NAME
do
  RESULT=$(\
    gcloud compute project-info describe --project ${ID} \
    --flatten=quotas \
    --format="csv[no-heading](quotas.metric,quotas.limit,quotas.usage)")
  # Prefix ${ID} to each line in the result
  for LINE in ${RESULT}
  do
    echo ${ID},${LINE}
  done
done

it is important that the account authenticated has the role project/viewer over all projects associated, also Compute Engine API must be enabled in the projects.

Having said that, you can create a service account associated per organization or by folder in order to get all necessary information.

Jan Hernandez
  • 4,414
  • 2
  • 12
  • 18