How to get all instance with a tag number in GCP compute engine

71 Views Asked by At

I want to get all instance id or list of all instance based on tag in GCP compute engine using Google compute engine sdk.

Can someone guide me how i can do this?

1

There are 1 best solutions below

1
Kapil Sakhare On

You can filter results from list commands with regular expressions by including the --filter flag as shown in this official GCP document.

Use the filter in command as shown below:

“gcloud compute instances list --filter="tags:tag1"”

Replace “tag1” in the above command with the tag you have used for your instances so that you will get only instances with the mentioned tag.