Unable to delete project due to ghost subnetwork and instance

Problem

Project deletion fails with the following subnetwork error:

The subnetwork resource 'projects/(HOST_PROJECT)/regions/(HOST_REGION)/subnetworks/(HOST_SUBNETWORK)' is already being used by 'projects/(NONHOST_PROJECT)/zones/(ZONE)/instances/(INSTANCE_GROUP(fromnonhost_project))'

Environment

  • Google Compute Engine VM
  • Google Cloud Console

Solution

  1. Delete active resources on Serverless Virtual Private Cloud (VPC) access that are being used by instances from other instance groups.
  2. Delete any reserved Internet Protocol (IP) address present in the project [ project that is targeted to be deleted ].

Cause

Whenever subnetwork resource of a project is used by instances of other instance groups, along with this project having a reserved Internet Protocol (IP) Address, you may see an error message when trying to delete this project. This is due to shared resources being used by other active resources from other active instance groups and projects. Deleting the subnetwork resources (present as active resources on Serverless Virtual Private Cloud (VPC) access under the VPC Network page in Google Cloud Console) along with the reserved IP relieves the network dependency of the project, enabling a delete action on it successfully.