Delete a Compute Engine instance (original) (raw)
Discover
Get started
Create instances
Create multiple VMs
- Create a managed instance group (MIG)
* Basic scenarios for creating MIGs
* Create a MIG in a single zone
* Create a MIG in multiple zones in a region
* Create a MIG with multiple machine types
* Create a MIG from an existing VM
* Create a MIG with autoscaling
* Create a MIG with Flex-start VMs
* Create a MIG with Spot VMs
* Create a MIG that adds GPU VMs all at once
* Create a MIG with stateful configuration
- Create a managed instance group (MIG)
Create sole-tenant VMs
Migrate VMs
Connect to VMs
Connect to a VM
- About SSH connections
- Linux VMs
* Connect to VMs
* SSH-in-browser
* Connect as the root user
* Connect using service accounts
* Configure apps to use SSH - Windows VMs
* Connect to Windows VMs using RDP
* Connect to a Windows VM's SAC
* Connect to Windows VMs using SSH
* Connect to Windows VMs using PowerShell
Manage access to VMs
Manage storage
Add disks to VMs
Make disks highly available
Back up and restore
Manage VMs
Basic operations and lifecycle
- VM instance lifecycle
- View VM properties
* Check that a VM is running
* View a list of VMs
* View the details of a VM
* View the UUID of a VM
* View the topology of a VM
* View the source image of a VM
* View referrers to VMs
* View network configuration of a VM
* View the number of visible CPU cores in a VM
Manage multiple VMs
- Manage groups of VMs
* Work with managed VMs in a MIG
* View info about MIGs and managed instances
* Add or remove VMs in a MIG
* Limit the run time of VMs in a MIG
* Add instances all at once in a MIG
* Overview
* Delete a MIG
- Manage groups of VMs
Host maintenance events
Securing VMs
Manage operating systems
Manage OS images
Manage licenses
Manage VM extensions
Deploy workloads
Applications
Databases
- MySQL
* MySQL on Compute Engine
* Install MySQL on Compute Engine
* Configure MySQL on Compute Engine
* Set up client access with a private IP address
* Cloning a MySQL database on Compute Engine
* Architectures for high availability of MySQL clusters on Compute Engine
* Deploying a highly available MySQL 5.6 cluster with DRBD on Compute Engine - SQL Server
* Best practices for SQL Server VMs
* Create
* Create a high-performance SQL Server VM
* Add a SQL Server license to an existing Linux server
* Add a SQL Server license to an existing Windows server
* Configure
* Set up AlwaysOn availability groups using an internal load balancer
* Set up AlwaysOn availability groups using a distributed network name
* Set up a failover cluster VM that uses S2D
* Set up a failover cluster VM with multi-writer disks
* Set up a SQL Server cluster on Linux with Always On availability groups and Pacemaker
* Migrate
* Migrate a SQL Server database from AWS EC2 to Compute Engine
* Migrate a SQL Server database from Windows to Linux
* Disaster recovery
* Disaster recovery for Microsoft SQL Server
* Disaster recovery for Microsoft SQL server on Persistent disk
* Disaster recovery for Microsoft SQL server on Hyperdisk
* Deploying Microsoft SQL Server for multi-regional disaster recovery
* Back up SQL Server databases to a Google Cloud Storage bucket
* Back up SQL Server databases using instant snapshots
* Cloning a Microsoft SQL Server database on Compute Engine
* Load test SQL Server using HammerDB
- MySQL
Containers
- Containers on Compute Engine
- Deploy containers on VMs and managed instance groups
- Configure options to run your container
- OpenShift workloads
* OpenShift on Google Cloud overview
* Plan for OpenShift on Google Cloud
* Overview of Cluster Services for OpenShift
* Built-in integrations for OpenShift
* Best practices for high availability with OpenShift
* Disaster recovery for OpenShift on Google Cloud
* Disaster recovery strategies for active-passive and active-inactive setups with OpenShift
Microsoft Windows
Monitor
Monitor logs
Scale
Load balancing
Optimize
Network performance
Troubleshoot
Delete a Compute Engine instance
This document explains how to delete a Compute Engine instance. To learn more about the lifecycle of an instance, seeCompute Engine instance lifecycle.
If you no longer need an instance, then delete it to stop incurring charges for the instance and its attached resources.
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 init
If 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, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Required roles
To get the permissions that you need to delete a compute instance, ask your administrator to grant you theCompute 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 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.
Billing implications
After you delete a compute instance, you stop incurring charges for the instance and its attached resources, except in the following cases:
- If you delete an instance that is hosted on asole-tenant node, then you still incur charges for the sole-tenant node.
- If you delete an instance that is using areservation, then you continue to pay for the reserved resources until one of the following occurs:
- Compute Engine automatically deletes the reservation at your chosen date and time.
- You delete the reservation.
- You reduce the number of reserved instances in the reservation.
- If you have acommitted use discount, then you continue to pay for the committed resources, regardless if you use them or not.
- If you preserve any resources attached to the instance, such as disks, then you continue to pay for those resources until you delete them.
For more information, see VM instances pricing.
Preserve attached resources
In some cases, before you delete a compute instance, you might want to preserve one of its attached resources. You can preserve attached resources by doing 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 instance.
- To preserve a boot or non-boot disk, set theauto-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 an instance,unassign the IP address.
Delete instances
When you delete a compute instance, Compute Enginestops the instancebefore deleting it.
If you delete one or more instances simultaneously, then you must decide what happens to the attached disks:
- Delete instances and all attached resources
This option deletes the instances and deletes, or forces the deletion of, boot, non-boot, or all attached disks. - Delete instances and preserve disks
This option deletes the instances but preserves boot, non-boot, or all attached disks for later use.
Delete instances and all attached resources
Depending on what you want to do when deleting a compute instance, use the following options:
- If youconfigured an attached disk to be preservedupon instance deletion, then you can override this setting and force its deletion using the Google Cloud CLI.
- If you've enabledgraceful shutdown in the instance, then you can delete the instance without gracefully shutting it down or end an ongoing graceful shutdown using the Google Cloud console, gcloud CLI, or REST API.
- To delete multiple instances simultaneously, use the Google Cloud console or, for instances located in the same zone, the gcloud CLI.
To delete one or more instances and all attached resources, select one of the following options:
Console
- In the Google Cloud console, go to the VM instances page.
Go to VM instances - Select the instances that you want to delete.
- Click Delete.
- In the dialog, do the following:
- Optional: To delete the instances without gracefully shut them down, or end an ongoing graceful shutdown, select theSkip graceful shutdown (if applicable) checkbox.
- To confirm, click Delete.
gcloud
To delete one or more instances in the same zone, use thegcloud compute instances delete command:
gcloud compute instances delete INSTANCE_NAMES \
--zone=ZONE
Replace the following:
INSTANCE_NAMES: a list of instance names separated by spaces—for example,instance-01 instance-02 instance-03.ZONE: the zone where the instances are located.
Optionally, you can do one or both of the following:
- To force the deletion of the disks attached to one or more instances, include the
--delete-disksflag:
gcloud compute instances delete INSTANCE_NAMES \
--delete-disks=DELETE_DISK_TYPE \
--zone=ZONE Replace DELETE_DISK_TYPE with one of the following values:
- To delete attached boot and non-boot persistent storage:
all - To delete only attached boot persistent storage:
boot - To delete only non-boot persistent storage:
data - If you've enabled graceful shutdown in one or more instances, then you can delete the instances without gracefully shutting them down, or manually end an ongoing graceful shutdown. To do so, use thegcloud beta compute instances delete commandwith the
--no-graceful-shutdownflag:
gcloud beta compute instances delete INSTANCE_NAMES \
--no-graceful-shutdown \
--zone=ZONE C#
Go
Java
Node.js
PHP
Python
Ruby
REST
To delete an instance, make a DELETE request to theinstances 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 instance is located.ZONE: the zone of the instance.INSTANCE_NAME: the instance name.
Optionally, if you've enabled graceful shutdown in the instance, you can delete the instances without gracefully shutting it down, or manually end an ongoing graceful shutdown. To do so, make a DELETE request to thebeta instances.delete method. In the request URL, include the noGracefulShutdown query parameter set totrue:
DELETE https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME?noGracefulShutdown=true
Delete instances and preserve disks
By default, deleting a compute instance deletes the instance and its attached resources. However, when you delete an instance using the gcloud CLI, you can specify to preserve the attached disks, regardless of theirauto-delete settings.
To delete one or more instances in the same zone while preserving their attached disks, use thegcloud compute instances delete commandwith 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 instance names separated by spaces—for example,instance-01 instance-02 instance-03.KEEP_DISK_TYPE: specify one of the following values:- To preserve attached boot and non-boot persistent storage:
all - To preserve only attached boot persistent storage:
boot - To preserve only attached non-boot persistent storage:
data
- To preserve attached boot and non-boot persistent storage:
ZONE: the zone where the instances are located.
Optionally, if you've enabledgraceful shutdown in one or more instances, you can delete the instances without gracefully shutting them down, or manually end an ongoing graceful shutdown. To do so, use thegcloud beta compute instances delete commandwith the --no-graceful-shutdown flag:
gcloud beta compute instances delete VM_NAMES \
--keep-disks=KEEP_DISK_TYPE \
--no-graceful-shutdown \
--zone=ZONE
What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-18 UTC.