1
votes

I tried to stop a vm instances using

gcloud compute instances stop instance-2-1

It throws an error as follows:

ERROR: (gcloud.compute.instances.stop) Could not fetch resource: - The resource 'projects/white-stacker-182910/zones/asia-southeast1-a/instances/instance-2-1' was not found

I launched my instance in asia-southeast-1-b

I cant stop the instances in a specific region or zone except asia-southeast1-a

How can i stop an instances regardless of regions and zones. Or how can i stop an instance by specifying the region and zone along with it.

2

2 Answers

0
votes

Do:

gcloud config set compute/zone asia-southeast1-a

Then

gcloud compute instances stop instances-2-1

It will work.

Refer: https://cloud.google.com/compute/docs/gcloud-compute/#set_default_zone_and_region_in_your_local_client

0
votes

You can specify the zone via flag

gcloud compute instances stop instance-2-1 --zone asia-southeast1-a

or via environment variable

CLOUD_SDK_COMPUTE_ZONE=asia-southeast1-a gcloud compute instances stop instance-2-1

useful when you have a terminal window dedicated to working on one zone, while another terminal for different zone.

As Ebins post mentioned you can also set global property for zone (it essentially adds --zone flag to each command)

gcloud config set compute/zone asia-southeast1-a

To stop instance-2-1 in all/any zones

gcloud compute instances stop \
  $(gcloud compute instances list --filter="name:instance-2-1" --uri)