Delete a Compute Engine instance (original) (raw)

Skip to main content

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

Console

When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

gcloud

  1. 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.
  2. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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.

  1. Install the Google Cloud CLI.
  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
  3. 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:

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:

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:

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

Depending on what you want to do when deleting a compute instance, use the following options:

To delete one or more instances and all attached resources, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Select the instances that you want to delete.
  3. Click Delete.
  4. In the dialog, do the following:
    1. Optional: To delete the instances without gracefully shut them down, or end an ongoing graceful shutdown, select theSkip graceful shutdown (if applicable) checkbox.
    2. 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:

Optionally, you can do one or both of the following:

gcloud compute instances delete INSTANCE_NAMES \  
    --delete-disks=DELETE_DISK_TYPE \  
    --zone=ZONE  

Replace DELETE_DISK_TYPE with one of the following values:

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:

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:

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.