Reputation: 6109
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.
Upvotes: 3
Views: 649
Reputation: 8980
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)
Upvotes: 2
Reputation: 6109
Do:
gcloud config set compute/zone asia-southeast1-a
Then
gcloud compute instances stop instances-2-1
It will work.
Upvotes: 2