· 5 years ago · Mar 04, 2021, 11:28 AM
1# /bin/bash
2# Propose:
3# 1. Export all id resources from a subscription.
4# 2. Save a CSV file with all resources information.
5#
6# Developed by: Alberto Perrote Sánchez.
7
8# Create folder where save data
9
10mkdir gcp_data
11
12# Install jq
13
14apt install jq
15
16# Export data with GCP API.
17# Change <API_KEY> to our proyect api key
18
19curl -s https://cloudbilling.googleapis.com/v1/services?key=API_KEY> gcp_data/gcp_proyect_services.json
20
21# Convert txt to csv.
22
23cat gcp_data/gcp_proyect_services.json | jq -r '.services | ["name", "serviceId", "displayName", "businessEntityName"],(to_entries| .[] | [ .value.name, .value.serviceId, .value.displayName, .value.businessEntityName, .key]) | @csv' > gcp_data/gcp_proyect_services.csv
24