10

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.

junsid
  • 335
  • 3
  • 14

1 Answers1

15

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)'
Jofre
  • 3,718
  • 1
  • 23
  • 31
  • Thanks so much for this -- exactly what I was looking for + had been trying to recreate. What does the `[]` do there exactly? Seems to return the result fine even without that. – chinabuffet Apr 17 '18 at 17:03
  • 2
    The `[]` are for the arguments. Indeed, they are not required in this instance, but I like to keep the brackets as a good practice to show I'm passing no arguments, and to avoid forgetting them when I need to pass them. – Jofre Apr 17 '18 at 17:29