Kishor Unnikrishnan
Kishor Unnikrishnan

Reputation: 2579

How to find all resources that exists inside a GCP subnet?

Is there a way I can find the resources inside a GCP Subnet inside my VPC.? Resources includes VM's and Databases.

Upvotes: 4

Views: 3883

Answers (2)

natbob1
natbob1

Reputation: 318

This can be accomplished from the IP addresses view in the GCP console and using the subnet property to filter resources.

Upvotes: 0

Daniel Ocando
Daniel Ocando

Reputation: 3764

There is not a straightforward command that will provide you a list of all the resources inside a GCP subnetwork (but I think it could be a good Feature Request if you create one in the VPC component on the following link).

The process should be done systematically per specific product and using filters.

For example, if you wanted to list all Compute Engine instances associated to a specific subnetwork in a specific region substituting the relevant information in the following gcloud command:

gcloud compute instances list --filter="networkInterfaces.subnetwork:projects/[CHANGE-FOR-PROJECT-ID]/regions/[E.G us-central1]/subnetworks/[NAME-OF-SUBNET]"

or to see the instances associated with a network you could use:

gcloud compute instances list --filter="networkInterfaces.network:projects/[CHANGE-FOR-PROJECT-ID]/global/networks/[NAME-OF-VPC-NETWORK e.g. default]"

In the case of databases (assuming you are referring to Cloud SQL instances), as described on the diagrams on the docs of Private IP the instances are hosted in another project and a similar approach as to the one explained with Compute Engine instances will only work (or make sense) if the instance has Private IP enabled, where you could check the information using the following filter:

gcloud sql instances list --filter="settings.ipConfiguration.privateNetwork:projects/[CHANGE-FOR-PROJECT-ID]/global/networks/[NAME-OF-VPC-NETWORK e.g. default]" 

So you should identify which resources related to each network or subnetwork are important for you to know exist and you could group the different gcloud xxx list commands in a script to print the required information.

Upvotes: 1

Related Questions