Search code examples
bashgoogle-cloud-platformreport

How do I generate a report for all project IDs, Account Owners, Creation Date and Current Labels in GCP?


I have a script that gives me project ID and owner, but I am trying to get the creation date of the project in my Organization and the current labels.

for PROJECT in `gcloud projects list --format="value(projectId)"`
do
   printf "%s:\n" ${PROJECT}
   gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members[]" --filter="bindings.role=roles/owner" --format="value(bindings.members)"
   printf "\n" 
done

Solution

  • Step 1:

    In first step we are collecting the project IDs by using gcloud projects list command in cloud shell.

    Step 2:

    For all Project Account Owners information, we need to run below script.

    ROLE="roles/owner" 
    for PROJECT in $(\
    gcloud projects list
     --formate"value (projectId)" \
    --filter="projectId something")
    do
    printf "%s:\n" ${PROJECT)
    gcloud projects get-iam-policy $(PROJECT} \ --flatten="bindings[ ].members [ ]" \\ --filter="bindings.role=${ROLE)" \ 
    --format-"value (bindings.members)" 
    printf "\n" 
    done
    

    Step 3:

    To find out Creation date for each project, we need to analyse the Admin Activity audit log in GCP console.

    Google Cloud services write audit logs that record administrative activities and accesses within your Google Cloud resources. Audit logs help you answer, "who did what, where, and when?" within your Google Cloud resources with the same level of transparency as in on-premises environments.

    Step 4:

    For getting the Current Labels information, we can view a project's label by calling the

    projects.get() method. This requires the resourcemanager.projects.get permission.