Ajinkya16
Ajinkya16

Reputation: 335

Google Cloud Labels Acces by api

How do I get the labels for all the resources in GCP with the use of api? Is there any specific api to access or view all the labels of all resources for a given project?

Upvotes: 2

Views: 719

Answers (1)

Fariya Rahmat
Fariya Rahmat

Reputation: 3220

You can view labels for resources by using the Cloud Console, the gcloud tool, or the Compute Engine API. To view labels for forwarding rules, use the gcloud tool or the Compute Engine API.

To retrieve labels with the use of api, make a GET request to the following resource:

  1. For VM instances, use the instances.setLabels() method.

  2. For snapshots, use the snapshots.setLabels() method.

  3. For images, use the images.setLabels() method.

  4. For disks, use the disks.setLabels() method.

  5. For forwarding rules, use the beta forwardingRules.setLabels() method.

  6. For regional static external IP addresses, use the beta addresses.setLabels() method.

  7. For global static external IP addresses, use the beta globalAddresses.setLabels() method.

  8. For VPN tunnels, use the beta vpnTunnels.setLabels() method.

For example, the following snippet makes a GET request to retrieve labels for a VM instance:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME

Refer to the document on Creating and Managing Labels.

Upvotes: 1

Related Questions