A virtual machine (VM) instance's ID lets you reference it with an immutable value.
Before you begin
- If you want to use the command-line examples in this guide, do the following:
- Install or update to the latest version of the Google Cloud CLI.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Get the ID of a VM instance
Console
Go to the VM instances page.
Click the Name of the VM instance.
In Basic information > Instance Id, view the VM instance ID.
gcloud
Get the instance ID by using the gcloud compute instances describe
command. This command
returns the instance ID as a string in the id
field.
gcloud compute instances describe INSTANCE_NAME
Replace INSTANCE_NAME
with the name of the instance.
API
Get the instance ID by using the instances.get
method. This method returns
the instance ID as a string value for the id
in the response body.
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
Replace the following:
PROJECT_ID
: ID of the project containing the instance to get the ID ofZONE
: zone containing the instance to get the ID ofINSTANCE_NAME
: name of the instance to get the ID of