Search code examples
google-cloud-platformgoogle-bigquerygoogle-data-catalog

Attach a tag along with the values to a BigQuery table using the Data Catalog


I have multiple tables in BigQuery. I also have a tag template. Is there a way to attach this tag template and fill the details programmatically with python to any table using the google.cloud.datacatalog?

tag = datacatalog.Tag()
tag.template = 'my_project_id.my_tag_template'

data_sources_field = datacatalog.TagField()
data_sources_field.string_value = 'Test_data_source'
tag.fields['data_sources'] = data_sources_field

datacatalog_client.create_tag(parent=my_table_entry.name,
                              tag=tag)

I get the following error -

PermissionDenied: 403 Permission denied on resource project my_project_id.my_tag_template.

The service account has 'project editor' role.


Solution

  • The issue was caused by the way the tagTemplate was called.

    tag.template = 'projects/<project-id>/locations/<location>/tagTemplates/<template_id>'

    Calling like above solved the issue.