VPC Network deletion fails because the network resource is already being used by an instance

Problem

VPC Network deletion fails with error message: 

ERROR: The network resource 'projects/(PROJECT_ID)/global/networks/(NETWORK)' is already being used by 'projects/(PROJECT_ID)/global/networkInstances/(NETWORK_INSTANCE_ID)".

Environment

Guidelines regarding Deleting a VPC Network were followed before attempting to delete the VPC Network; none of the following components refer to the VPC Network in question:

  • Cloud VPN gateways
  • Cloud Routers
  • firewall rules
  • custom static routes.

At least one Serverless Service (Cloud Functions, App Engine, Cloud Run) is currently in use.

All Serverless VPC Access Connectors referring to the VPC Network in question, that were in use by Serverless Services that still exist, have been deleted before attempting to delete the VPC Network. Check for recent Serverless VPC Access connectors' deletion events using this filter:

protoPayload.serviceName="vpcaccess.googleapis.com"

protoPayload.methodName="google.cloud.vpcaccess.v1.VpcAccessService.DeleteConnector"

At least one Serverless Service refers to at least one Serverless VPC Access connector that no longer exists, i.e. the referenced connector does not appear in the list of connectors in the Console under VPC Network > Serverless VPC Access. Follow the below instructions to find connector references in Serverless Services:

  1. In App Engine Standard Environment navigate to App Engine > Versions > Config column
  2. Click View and check for references of vpc_access_connector in the yaml.
  3. In Cloud Functions navigate to Cloud Functions > Select Cloud Function > Select version > Details tab > Network settings pane. Do this for all versions of the Cloud Function.
  4. In Cloud Run navigate to Cloud Run > Select instance > Revisions > Connections > VPC Connector.

Solution

  1. Remove any references of deleted Serverless VPC Access Connectors from Serverless Services that still reference them, and re-deploy the affected Serverless Services.
  2. Retry deleting the VPC Network in question.

Cause

Deleting a Serverless Access VPC connector does not automatically remove the reference of the connector from the Serverless Service that was using it prior to its deletion.