Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud command to retrieve metadata of a specific key

Is there any way to retrieve custom instance metadata value for a specific key ? I tried gcloud compute instances describe instance-1 command, this return whole meta data text. But i just want to retrieve the value of a specific key only.

like image 461
junsid Avatar asked Feb 21 '18 10:02

junsid


People also ask

How do I find the VM metadata?

To retrieve the VM metadata, make an HTTP GET request to one of the following addresses: http://gw/skytap ; the hostname gw automatically maps to the gateway IP address. http://<network-gateway-IP-address>/skytap ; for example, if the gateway IP address is 10.0. 0.254 , use http://10.0.0.254/skytap .

What is instance metadata in GCP?

Google Cloud Platform provides a metadata server that knows details about your App Engine instance, such as its containing project ID, service accounts, and tokens used by the service accounts. You can access this data using simple HTTP requests: no client libraries are required.

What are gcloud commands?

What is the gcloud CLI? The Google Cloud CLI is a set of tools to create and manage Google Cloud resources. You can use these tools to perform many common platform tasks from the command line or through scripts and other automation.


1 Answers

The gcloud tool has built-in filters and formats, for details you can read gcloud topic filters, gcloud topic formats, and gcloud topic projections.

For your specific use case, you can get the metadata value with:

gcloud compute instances describe INSTANCE-ID \
  --format='value[](metadata.items.YOUR-KEY)'
like image 57
Jofre Avatar answered Sep 25 '22 21:09

Jofre