List policy tags

List existing policy tags.

Code sample


Before trying this sample, follow the Go setup instructions in the Data Catalog quickstart using client libraries. For more information, see the Data Catalog Go API reference documentation.

To authenticate to Data Catalog, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import (

	datacatalog ""

// listPolicyTags prints information about the policy tags within a given taxonomy
// resource.
func listPolicyTags(w io.Writer, parentTaxonomyID string) error {
	// parentTaxonomyID := projects/myproject/locations/us/taxonomies/1234"
	ctx := context.Background()
	policyClient, err := datacatalog.NewPolicyTagManagerClient(ctx)
	if err != nil {
		return fmt.Errorf("datacatalog.NewPolicyTagManagerClient: %w", err)
	defer policyClient.Close()

	req := &datacatalogpb.ListPolicyTagsRequest{
		Parent: parentTaxonomyID,
	it := policyClient.ListPolicyTags(ctx, req)
	fmt.Fprintf(w, "listing policy tags in taxonomy %s\n", parentTaxonomyID)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
		if err != nil {
			return fmt.Errorf("ListPolicyTags iteration error: %w", err)

		fmt.Fprintf(w, "\t- %s (%s)", resp.Name, resp.DisplayName)
		if resp.ParentPolicyTag != "" {
			fmt.Fprintf(w, " has parent Tag %s", resp.ParentPolicyTag)
	return nil

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.