Scott C.
Scott C.

Reputation: 51

List ALL GCP Resources a Tag is attached to

According to GCP Documentation for Tags: To delete a tag value, you must first remove it from all resources. A tag value that is still attached to a resource will not be deleted.

If you have numerous resources where this tag is used (across Buckets, BQ Datasets, VMs, IAM, etc.) it can be cumbersome to check every resource page to identify where this tag is used.

Is there a CLI command that lists all places where a tag value is used?

This is useful:

  1. If a tag deletion is failing because it used somewhere but you don't know where.
  2. If you want to edit/extend functionality of an existing tag value and want an audit of everywhere it is currently utilized to ensure edits are made where required.
  3. When Google tries to delete a tag value I'm sure it already runs a similar check in the background to ensure a successful deletion.

Upvotes: 0

Views: 48

Answers (1)

p_lycs
p_lycs

Reputation: 184

Use the CLI command below to show a list of Tags attached to a specific resource:

gcloud resource-manager tags bindings list --parent=//cloudresourcemanager.googleapis.com/projects/PROJECT_ID

As an expected result, it should only show the inherited key-tag value pairs that are under the projects, which is the tag value.

For additional information, you can check the gcloud resource-manager tags bindings list.

Upvotes: 0

Related Questions