プロジェクトで Data Catalog タグ テンプレートを作成したら、組織のメンバーに Data Catalog tagTemplateUser ロールを付与すると、組織のメンバーがテンプレートを使用してデータリソースにタグ付けできるようになります(GCP リソースへのタグ付けをご覧ください)。
次のセクションでは、メンバーに tagTemplateUser
のロールを付与する方法を示します。
tagTemplateUser ロールを付与する
Console
Google Cloud Console の [IAM] ページでメンバーのリストの右にある編集(鉛筆)アイコンをクリックして、プロジェクトのメンバーに Data Catalog tagTemplateUser
のロールを付与します。

[権限の編集] ダイアログが開きます。[別のロールを追加] をクリックし、[ロールを選択] ボックスをクリックします。「data catalog」と入力してフィルタを追加し、使用可能な Data Catalog のロールを一覧表示します。[Data Catalog TagTemplate ユーザー] ロールをクリックしてロールを選択し、[保存] をクリックしてダイアログを閉じます。

Python
"""This application demonstrates how to allow a project member to use a Template in order to create Tags with the Cloud Data Catalog API. For more information, see the README.md under /datacatalog and the documentation at https://cloud.google.com/data-catalog/docs. """ import argparse from google.cloud import datacatalog_v1 def grant_tag_template_user_role(project_id, template_id, member_id): """Grants a user the Tag Template User role for a given template.""" datacatalog = datacatalog_v1.DataCatalogClient() # Currently, Data Catalog stores metadata in the us-central1 region. location = "us-central1" # Format the Template name. template_name = datacatalog_v1.DataCatalogClient.tag_template_path( project_id, location, template_id) # Retrieve Template's current IAM Policy. policy = datacatalog.get_iam_policy(template_name) # Add Tag Template User role and member to the policy. binding = policy.bindings.add() binding.role = 'roles/datacatalog.tagTemplateUser' binding.members.append(member_id) # Update Template's policy. datacatalog.set_iam_policy(template_name, policy) if __name__ == '__main__': parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument('project_id', help='Your Google Cloud project ID') parser.add_argument('template_id', help='Your Template ID') parser.add_argument('member_id', help='Member who will be granted access,' ' e.g. \'user:test-user@gmail.com\'') args = parser.parse_args() grant_tag_template_user_role( args.project_id, args.template_id, args.member_id)
Java
/* This application demonstrates how to allow a project member to use a Template in order to create Tags with the Cloud Data Catalog API. For more information, see the README.md under /datacatalog and the documentation at https://cloud.google.com/data-catalog/docs. */ package com.example.datacatalog; import com.google.cloud.datacatalog.v1.DataCatalogClient; import com.google.cloud.datacatalog.v1.TagTemplateName; import com.google.iam.v1.Binding; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; public class AllowMemberUseTemplate { public static void grantTagTemplateUserRole() { // TODO(developer): Replace these variables before running the sample. String projectId = "my-project"; String tagTemplateId = "my_tag_template"; String memberId = "user:test-user@gmail.com"; grantTagTemplateUserRole(projectId, tagTemplateId, memberId); } /** * Grant a project member the Tag Template User role for a given template. * * @param projectId The project ID to which the Template belongs, e.g. 'my-project'. * @param templateId The template ID to grant access, e.g. 'my_template'. * @param memberId The member ID who access will be granted to, e.g. 'user:test-user@gmail.com'. */ public static void grantTagTemplateUserRole( String projectId, String templateId, String memberId) { // Currently, Data Catalog stores metadata in the us-central1 region. String location = "us-central1"; // Format the Template name. String templateName = TagTemplateName.newBuilder() .setProject(projectId) .setLocation(location) .setTagTemplate(templateId) .build() .toString(); // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. try (DataCatalogClient dataCatalogClient = DataCatalogClient.create()) { // Create a Binding to add the Tag Template User role and member to the policy. Binding binding = Binding.newBuilder() .setRole("roles/datacatalog.tagTemplateUser") .addMembers(memberId) .build(); // Create a Policy object to update Template's IAM policy by adding the new binding. Policy policyUpdate = Policy.newBuilder() .addBindings(binding) .build(); SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setPolicy(policyUpdate) .setResource(templateName).build(); // Update Template's policy. dataCatalogClient.setIamPolicy(request); System.out.println(String.format("Role successfully granted to %s", memberId)); } catch (Exception e) { System.out.print("Error during AllowMemberUseTemplate:\n" + e.toString()); } } }
Node.js
/** * This application demonstrates how to grant a project member * the Tag Template User role for a given template. * For more information, see the README.md under /datacatalog and the * documentation at https://cloud.google.com/data-catalog/docs. */ const main = async ( projectId = process.env.GCLOUD_PROJECT, templateId, memberId ) => { // ------------------------------- // Import required modules. // ------------------------------- const { DataCatalogClient } = require('@google-cloud/datacatalog').v1; const datacatalog = new DataCatalogClient(); const location = 'us-central1'; // Format the Template name. const templateName = datacatalog.tagTemplatePath( projectId, location, templateId ); // Retrieve Template's current IAM Policy. const [getPolicyResponse] = await datacatalog.getIamPolicy({ resource: templateName }); const policy = getPolicyResponse; // Add Tag Template User role and member to the policy. policy.bindings.push({ role: 'roles/datacatalog.tagTemplateUser', members: [memberId], }); const request = { resource: templateName, policy: policy, }; // Update Template's policy. const [updatePolicyResponse] = await datacatalog.setIamPolicy(request); console.log(`Iam policy: ${JSON.stringify(updatePolicyResponse)}`); }; // node grantTagTemplateUserRole.js// sample values: // projectId = 'my-project'; // templateId = 'my-template'; // memberId = 'user:member@gmail.com'; main(...process.argv.slice(2));
REST とコマンドライン
ご使用の言語の Cloud クライアント ライブラリにアクセスしない場合、または REST リクエストを使用して API をテストする場合は、次の例を参照して、Data Catalog REST API のドキュメントをご覧ください。
後述のリクエストのデータを使用する前に、次のように置き換えます。
- project-id: GCP プロジェクト ID
- template-id: タグ テンプレート ID
HTTP メソッドと URL:
POST https://datacatalog.googleapis.com/v1/projects/project-id/locations/us-central1/tagTemplates/template-id:setIamPolicy
JSON 本文のリクエスト:
{ "policy":{ "bindings":[ { "role":"roles/datacatalog.tagTemplateUser", "members":[ "user:username@gmail.com" ] } ] } }
リクエストを送信するには、次のいずれかのオプションを展開します。
次のような JSON レスポンスが返されます。
{ "version":1, "etag":"xxxxx.....", "bindings":[ { "role":"roles/datacatalog.tagTemplateUser", "members":[ "user:username@gmail.com" ] } ] }