Dusan Gligoric
Dusan Gligoric

Reputation: 584

add labels to multiple GCP compute instances at the same time

can I update multiple GCP instances using gcloud at the same time? I am looking to add label to all my instances and I don't see a way to do it for multiple instances at the time like AWS has with its awscli.

i can do

gcloud compute instances update test-instance --update-labels test=foo

would want something like

gcloud compute instances update test-instance1 test-instance2 --update-labels test=foo

Upvotes: 0

Views: 2460

Answers (1)

DazWilkin
DazWilkin

Reputation: 40091

To my knowledge, no there isn't. However it's straightforward to use a shell (e.g. bash) to enumerate the list of instances and run the command for each:

for INSTANCE in "test-instance1" "test-instance2"
do
  gcloud compute instances update ${INSTANCE} --update-labels ...
done

The command appears to not support the --async flag so you will need to run these commands sequentially, unless you throw them into the background.

This approach is less elegant than being able to issue one command that effects multiple updates (service-side) but I suspect it's a relatively infrequent requirement and, for smaller number of instances, the existing command is probably sufficient.

You may combine the update with e.g. an instances list:

for INSTANCE in $(gcloud compute instances list --format="value(name)")
...

You can submit a feature request to Google:

https://issuetracker.google.com/issues/new?component=187143&template=1163129

Upvotes: 3

Related Questions