GCP API for getting list of labels

Viewed 435

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.

2 Answers

Currently it's not possible to list all labels within a GCP project.

Beside what you mention about GCP Resource Manager API, you could get some information from Asset Inventory, however it won't fulfill your requirements.

To achieve what you want, you can fill a Feature Request in GCP IssueTracker to create this possibility.

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.

Related