如何查找哪些资源使用 GCP 中的 vpc?

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

我想删除一个 GCP vpc,我得到:

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

如何确定这些 other existing resources 是什么?

可以使用VPC网络的资源如下:

  • 子网
  • 静态内部 IP 地址
  • 防火墙规则
  • 路由(包括静态路由和创建的路由 automatically/dynamically)
  • VPC 网络对等互连
  • 私人服务连接
  • 实例

唯一的方法是手动检查每个类别并确保它们没有使用 VPC。

有关每种资源的更多信息,请访问此文档 [1]。

干杯!


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

GCP中有很多resources that relate directly to a VPC NW

两种列举方式:

  1. 您可以列出它们 directly with the API
  2. 您可以使用 this python script 列出其中的大部分。我猜你会在这里找到阻止你删除 NW 的资源。 输出如下所示:

--------------------------------------------
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']