schoon
schoon

Reputation: 3324

How do I find which resources use a vpc in GCP?

I want to delete a GCP vpc, I get:

Failed to delete the network. Error: Some of the resources are referenced by other existing resources and cannot be deleted.

How do I determine what these other existing resources are?

Upvotes: 1

Views: 2461

Answers (3)

Rishav7745
Rishav7745

Reputation: 11

Remove the subnets in the custom VPC you created, follow these steps:

Navigate to Your-VPC. Click on "SUBNETS" to access the list of subnets. Locate the delete icon next to each subnet in the list and click on it to delete them

By deleting subnets you will be able to delete the vpc now (Delete inctances, instances group if created in this vpc prior).

Upvotes: 1

Alon Lavian
Alon Lavian

Reputation: 1389

There are a lot of resources that relate directly to a VPC NW in GCP.

Two options of listing them:

  1. You can list them directly with the API
  2. You can use this python script to list most of them. My guess is you'll find the resource that blocks you from deleting the NW here. The output looks like this:

--------------------------------------------
Subnetworks in Network alon-test-network:
--------------------------------------------
https://www.googleapis.com/compute/v1/projects/alon-lavian/regions/us-central1/subnetworks/alon-test-network
https://www.googleapis.com/compute/v1/projects/alon-lavian/regions/asia-east1/subnetworks/subnet-2

--------------------------------------------
Instances in VPC alon-test-network:
--------------------------------------------
instance-3, zone: us-central1-a

--------------------------------------------
FW rules in Network alon-test-network:
--------------------------------------------
alon-test-network-allow-custom
alon-test-network-allow-http
alon-test-network-allow-https
alon-test-network-allow-icmp
default-allow-ssh-alon

--------------------------------------------
Routes in Network alon-test-network:
--------------------------------------------
default-route-d957345c6aef02c8 destination range: 10.128.0.0/20
default-route-dcecf66e898091c4 destination range: 10.0.0.0/9
default-route-fa59cdb8270a46ab destination range: 0.0.0.0/0

--------------------------------------------
VPN GW in Network alon-test-network:
--------------------------------------------
alon-vpn

--------------------------------------------
Routers in Network alon-test-network:
--------------------------------------------

--------------------------------------------
Addresses in Network alon-test-network:
--------------------------------------------
alon-address ,users: ['https://www.googleapis.com/compute/v1/projects/alon-lavian/zones/us-central1-a/instances/instance-3']

Upvotes: 0

BraveAdmin
BraveAdmin

Reputation: 774

The resources that can be using a VPC network are the following:

  • Subnets
  • Static Internal IP addresses
  • Firewall rules
  • Routes (including static and routes created automatically/dynamically)
  • VPC network Peering
  • Private Service connection
  • Instances

the only way is to check each category manually and make sure that are not using the VPC.

For more information regarding each kind of resource, visit this documentation [1].

Cheers!


[1] https://cloud.google.com/vpc/docs/vpc#specifications

Upvotes: 4

Related Questions