Is there an GCP API for getting labels for resources? I want to get a list of all labels for GCP Project. How to get all labels in GCP? Basically GCP Resource Manager API return the Lebel object for every resource. But I want to get list of all labels using one API call.
I tried the next workaround to get all the labels:
gcloud projects describe <YOUR-PROJECT-NAME> --format=json | jq -r '.labels|to_entries|map("\(.key)=\(.value|tostring)")|.[]'
You will receive a key=value list.
You could list for all the resources you want and filter what you need as @Bumeranghc said with the proper --format like (with jq for further manipulation): gcloud projects list --format=json | jq -r '.[].labels'
Without jq: gcloud projects list —-format=“json(projectId, labels)”
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With