Member-only story
Extract compute engine inventory from all projects under a GCP org
Inventory collection is an important IT operations task, whether it is for on-premise or cloud Infrastructure assets. In this post we are going to see how we can extract all the compute engine details for all the projects under a Google cloud platform org , most importantly extracting the information to a csv file.
By default, there is no one single gcloud command to extract instance name, machine type, operating system, cpu , memory and disk size from all the projects under an org to a csv file . It would be nice if google cloud can add this feature.
So lets see how can do this through shell script, python scripts and compute engine REST api.
Let’s see the steps involved,
- Get the list of projects.
- Iterate through projects
- Get the list of instances under that project
- Extract Instance name and zone information
- Pass the project name, instance name and zone to a python script
- use googleapiclient.discovery package and oauth2client.client.GoogleCredentials python packages for service request
- use instances_type.get method in compute engine rest api to get machine details, OS and disk size details.