Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP API for getting list of labels

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.

like image 744
Ganesh Jagdale Avatar asked Oct 19 '25 05:10

Ganesh Jagdale


2 Answers

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.

like image 135
Bumeranghc Avatar answered Oct 22 '25 04:10

Bumeranghc


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)”

like image 34
JuanToroMarty Avatar answered Oct 22 '25 02:10

JuanToroMarty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!