This page describes how to get, list, and delete instance templates.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Get information about an instance template
Console
- In the Google Cloud console, go to the Instance Templates page.
- Click the name of the instance template to see the details of the template.
gcloud
To get information about a regional or a global instance template, use the
instance-templates describe command
.
For a regional instance template, use the following command:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME \ --region=REGION
For a global instance template, use the following command:
gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME
Go
Java
Node.js
Python
REST
To get information about a regional instance template, use the
regionInstanceTemplates.get
method
as follows:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME
To get information about a global instance template, use the
instanceTemplates.get
as follows:
GET https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/instanceTemplates/[INSTANCE_TEMPLATE]
List instance templates
To get a list of instance templates you created:
Console
The Instance Templates page lists all of the instance templates in your project.
gcloud
To get a list of all regional instance templates, use the following command:
gcloud compute instance-templates list \ --regions
To get a list of regional instance templates in a specific region, use the following command:
gcloud compute instance-templates list \ --filter="region:(REGION)"
To get a list of global instance templates, use the following command:
gcloud compute instance-templates list \ --global
To get a list of all instance templates, including the regional and global, use the following command:
gcloud compute instance-templates list
Go
Java
Node.js
Python
REST
To get a list of regional instance templates, make a
regionInstanceTemplates.list
request:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/instanceTemplates
To get a list of global instance templates, make a
instanceTemplates.list
request:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates
Delete an instance template
Deleting an instance template removes it from your list of templates. You cannot delete an instance template if a managed instance group references it.
Console
- In the Google Cloud console, go to the Instance Templates page.
- Select the instance templates you want to delete.
- Click Delete.
gcloud
Using the Google Cloud CLI, run:
gcloud compute instance-templates delete INSTANCE_TEMPLATE_NAME
For a regional instance template, INSTANCE_TEMPLATE_NAME must
contain the full URL of the template. For example, https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/instanceTemplates/example-regional-instance-template
.
Go
Java
Node.js
Python
REST
To delete a regional instance template, make a
regionInstanceTemplates.delete
request:
DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME
To delete a global instance template, make a
instanceTemplates.delete
request:
DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates/INSTANCE_TEMPLATE_NAME
Sometimes the VMs in a managed instance group can be out of sync with the rest of the group, and use a different instance template than the rest of the group. If a VM in a managed instance group uses a different template than what is specified on the group, that VM will continue to use its template for repair even if that template is deleted. For more information about applying a new instance template, see Applying new configurations to VMs in a MIG.