This document explains how to permanently delete a Compute Engine instance.
If you no longer need a compute instance, then delete it to stop incurring charges for the compute instance and its attached resources. You can't recover the deleted compute instance. To learn more about the states that a compute instance goes through from its creation up to its deletion, see Compute Engine instance lifecycle.
Billing implications for deleted instances
After you delete a compute instance, you stop incurring charges for the compute instance and its attached resources, except in the following cases:
If you delete a compute instance that is hosted on a sole-tenant node, then you still incur charges for the sole-tenant node.
If you delete a compute instance that you created by using a reservation, then you continue to pay for the reserved resources until one of the following occurs:
You delete the reservation, or Compute Engine does so for an automatic operation.
You reduce the number of reserved compute instances in the reservation.
If you have a committed use discount, then you continue to pay for the committed resources, regardless if you use them or not.
If you preserve any resources that are attached to the compute instance, such as disks or external IP addresses, then you continue to pay for those resources until you delete them.
For more information, see VM instances pricing.
Before you begin
-
If you haven't already, set up authentication.
Authentication verifies your identity 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. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
C#
To use the .NET 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PHP
To use the PHP 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Ruby
To use the Ruby 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
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.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Preserve attached resources
If you want to preserve a resource that is attached to a compute instance before you delete it, then you can do one or more of the following:
To preserve a GPU attached to an N1 virtual machine (VM) instance, remove the GPU from the VM.
To preserve an attached disk, do one of the following:
To preserve a boot disk, detach the boot disk from the compute instance.
To preserve a boot or non-boot disk, set the auto-delete setting of the disk to
false.
To preserve the data of a Local SSD disk, copy the data of the disk to a persistent storage option.
To reuse the static external IP address of a compute instance, unassign the IP address.
Required roles
To get the permissions that
you need to delete a compute instance,
ask your administrator to grant you the
Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to delete a compute instance. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to delete a compute instance:
-
compute.instances.deleteon the compute instance -
To force the deletion of an attached disk:
compute.disks.deleteon the disk
You might also be able to get these permissions with custom roles or other predefined roles.
Delete compute instances
When you delete a compute instance, Compute Engine stops the compute instance before it's deleted. If you delete one or more compute instances simultaneously, then you must decide what happens to the attached disks:
Delete disks: you can delete the boot disks, non-boot disks, or all of its attached disks to your compute instances. If you configured your disks to be preserved upon deletion, then you can optionally override this configuration and force their deletion.
For instructions, see Delete compute instances and all attached resources.
Preserve disks: you can preserve boot disks, non-boot disks, or all of its attached disks to your compute instances.
For instructions, see Delete compute instances and preserve disks.
Delete compute instances and all attached resources
To delete compute instances in specific scenarios—such as forcing the deletion of attached disks, skipping or ending a graceful shutdown, or deleting multiple instances at the same time—use the appropriate method:
Force delete disks: if you've configured an attached disk to be preserved when Compute Engine deletes a compute instance, then you can override this setting and force its deletion by using the Google Cloud CLI.
Skip or end a graceful shutdown: if you've enabled graceful shutdown in the compute instance, then you can delete the compute instance without gracefully shutting it down or end an ongoing graceful shutdown by using the Google Cloud console, gcloud CLI, or REST API.
Delete multiple compute instances: if you want to delete multiple compute instances simultaneously, then use the Google Cloud console or, for multiple compute instances that exist in the same zone, the gcloud CLI.
To delete one or more compute instances and all of their attached resources, select one of the following options:
Console
In the Google Cloud console, go to the VM instances page.
Select the instances that you want to delete.
Click Delete. If there is no Delete option, then click More actions, and then select Delete.
In the dialog that appears, do the following:
Optional: To delete the compute instances without gracefully shutting them down, or to end an ongoing graceful shutdown, select the Skip graceful shutdown (if applicable) checkbox.
To confirm, click Delete.
gcloud
To delete one or more compute instances in the same zone, use the
gcloud compute instances delete command:
gcloud compute instances delete INSTANCE_NAMES \
--zone=ZONE
Replace the following:
INSTANCE_NAMES: a list of names of compute instances that you want to delete, separated by spaces. For example, specifyinstance-01 instance-02 instance-03.ZONE: the zone where the compute instances exist.
Optionally, you can include one or both of the following flags:
To force the deletion of the disks that are attached to one or more compute instances, include the
--delete-disksflag:gcloud compute instances delete INSTANCE_NAMES \ --delete-disks=DELETE_DISK_TYPE \ --zone=ZONEReplace
DELETE_DISK_TYPEwith the types of storage that you want to delete. Specify one of the following values:To delete boot and non-boot persistent storage:
allTo delete only boot persistent storage:
bootTo delete only non-boot persistent storage:
data
To skip or end an ongoing graceful shutdown, include the
--no-graceful-shutdownflag:gcloud compute instances delete INSTANCE_NAMES \ --no-graceful-shutdown \ --zone=ZONE
C#
Go
Java
Node.js
PHP
Python
Ruby
REST
To delete a compute instance, make a DELETE request to the
instances delete method:
DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
Replace the following:
PROJECT_ID: the ID of the project where the compute instance exists.ZONE: the zone where the compute instance exists.INSTANCE_NAME: the name of the compute instance.
If you want to skip or end an ongoing graceful shutdown, then include the
noGracefulShutdown query parameter set to true in the request URL:
DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME?noGracefulShutdown=true
Delete compute instances and preserve disks
By default, deleting a compute instance deletes the compute instance and its attached resources. However, when you delete a compute instance by using the gcloud CLI, you can specify to preserve the attached disks, regardless of their auto-delete settings.
To delete one or more compute instances in the same zone while preserving their
attached disks, use the
gcloud compute instances delete command
with the --keep-disks flag:
gcloud compute instances delete INSTANCE_NAMES \
--keep-disks=KEEP_DISK_TYPE \
--zone=ZONE
Replace the following:
INSTANCE_NAMES: a list of names of compute instances that you want to delete, separated by spaces. For example, specifyinstance-01 instance-02 instance-03.KEEP_DISK_TYPE: the types of disks that you want to preserve. Specify one of the following values:To preserve attached boot and non-boot persistent storage:
allTo preserve only attached boot persistent storage:
bootTo preserve only attached non-boot persistent storage:
data
ZONE: the zone where the compute instances exist.
If you've enabled
graceful shutdown in one
or more compute instances, then you can save costs by deleting the compute
instances without gracefully shutting them down, or by manually ending an
ongoing graceful shutdown. To do so, include the --no-graceful-shutdown flag
in the command:
gcloud compute instances delete VM_NAMES \
--keep-disks=KEEP_DISK_TYPE \
--no-graceful-shutdown \
--zone=ZONE