Certificate Manager イベントを Workflows に転送する

Eventarc トリガーは、特定のイベントまたは一連のイベントに関心があることを宣言します。イベント ルーティングを構成するには、トリガーのフィルタ(イベントソースとターゲット ワークフローを含む)を指定します。

イベントは、HTTP リクエストを介して CloudEvents 形式で配信されます。Workflows サービスは、CloudEvents 仕様に従ってイベントを JSON オブジェクトに変換し、ワークフロー ランタイム引数としてワークフロー実行に渡します。イベントサイズが 512 KB を超えていないことを確認してください。Workflows の引数サイズの上限を超えるイベントはワークフローの実行をトリガーしません。

以下では、Certificate Manager 直接イベントに応答してワークフローの実行がトリガーされるように、イベント ルーティングを構成する方法について説明します。詳細については、サポートされている直接イベントのリストをご覧ください。

トリガーを作成する準備

ターゲット ワークフローの Eventarc トリガーを作成する前に、次の作業を完了します。

コンソール

  1. Google Cloud コンソールのプロジェクト セレクタ ページで、Google Cloud プロジェクトを選択または作成します。

    プロジェクト セレクタに移動

  2. Eventarc API、Eventarc Publishing API、Workflows API、Workflow Executions API を有効にします。

    API を有効にする

  3. 該当する場合は、直接イベントに関連する API を有効にします。たとえば、 Certificate Manager イベントの場合はCertificate Manager API を有効にします。

  4. アカウントがない場合は、ユーザー管理のサービス アカウントを作成し、Eventarc がターゲット ワークフローのイベントを管理できるように、必要なロールと権限を付与します。

    1. Google Cloud コンソールで、[サービス アカウント] ページに移動します。

      [サービス アカウント] に移動

    2. プロジェクトを選択します。

    3. [サービス アカウント名] フィールドに名前を入力します。Google Cloud コンソールでは、この名前に基づいて [サービス アカウント ID] フィールドに値が設定されます。

      [サービス アカウントの説明] フィールドに説明を入力します。例: Service account for event trigger

    4. [作成して続行] をクリックします。

    5. 適切なアクセス権を付与するには、[ロールを選択] リストで、サービス アカウントに必要な Identity and Access Management(IAM)ロールを選択します。詳細については、Workflows ターゲットのロールと権限をご覧ください。

      ロールを追加するには、[別のロールを追加] をクリックして各ロールを追加します。

    6. [続行] をクリックします。

    7. アカウントの作成を完了するには、[完了] をクリックします。

gcloud

  1. Google Cloud コンソールで、「Cloud Shell をアクティブにする」をクリックします。

    Cloud Shell をアクティブにする

    Google Cloud コンソールの下部で Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。Cloud Shell はシェル環境です。Google Cloud CLI がすでにインストールされており、現在のプロジェクトの値もすでに設定されています。セッションが初期化されるまで数秒かかることがあります。

  2. Eventarc API、Eventarc Publishing API、Workflows API、Workflow Executions API を有効にします。

    gcloud services enable eventarc.googleapis.com \
        eventarcpublishing.googleapis.com \
        workflows.googleapis.com \
        workflowexecutions.googleapis.com
    

  3. 該当する場合は、直接イベントに関連する API を有効にします。たとえば、 Certificate Manager イベントの場合は certificatemanager.googleapis.com を有効にします。

  4. アカウントがない場合は、ユーザー管理のサービス アカウントを作成し、Eventarc がターゲット ワークフローのイベントを管理できるように、必要なロールと権限を付与します。

    1. サービス アカウントを作成します。

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      SERVICE_ACCOUNT_NAME は、サービス アカウントの名前に置き換えます。6~30 文字で、小文字の英数字とダッシュを使用できます。作成したサービス アカウントの名前は変更できません。

    2. 必要な Identity and Access Management(IAM)のロールまたは権限を付与します。詳細については、Workflows ターゲットのロールと権限をご覧ください。

トリガーを作成する

イベント レシーバとしてデプロイされたワークフローに Eventarc トリガーを作成するには、Google Cloud CLI(gcloud または Terraform)を使用するか、Google Cloud コンソールを使用します。

コンソール

  1. Google Cloud コンソールで、[Eventarc] の [トリガー] ページに移動します。

    [トリガー] に移動

  2. [トリガーを作成] をクリックします。
  3. トリガー名を入力します。

    これはトリガーの ID で、先頭は英字にする必要があります。63 文字以下とし、小文字、数字、ハイフンを使用することができます。

  4. [トリガーのタイプ] で、[Google のソース] を選択します。
  5. [イベント プロバイダ] リストで「Certificate Manager」を選択します。

    関連する Google Cloud のドキュメントでは、イベント プロバイダ名の前に Cloud または Google Cloud が付いていない場合があります。たとえば、Memorystore for Redis はコンソールで Google Cloud Memorystore for Redis と表示されます。

  6. [イベントタイプ] リストで、直接イベントからイベントタイプを選択します。
  7. イベント ペイロードのエンコードを指定するには、[イベントデータのコンテンツ タイプ] リストで application/json または application/protobuf を選択します。

    JSON 形式のイベント ペイロードは、Protobuf 形式のイベント ペイロードよりも大きくなります。イベントの宛先とイベントサイズの制限によっては、信頼性に影響する可能性があります。詳細については、既知の問題をご覧ください。

  8. [リージョン] リストで、[global (グローバル)] を選択します。

    詳細については、Eventarc のロケーションをご覧ください。

  9. イベント プロバイダで必要な場合は、[フィルタを追加] をクリックして、次の値を指定します。
    1. 選択した直接イベントに応じて、[属性 1] フィールドにイベント フィルタとして機能するリソース ID を選択します。
    2. 演算子を選択します。
    3. [属性の値 1] フィールドに、選択した演算子に応じて正確な値を入力するか、パスパターンを適用します。
    4. 適用可能な属性フィルタが他にもある場合は、[フィルタを追加] をクリックして適切な値を指定します。
  10. サービスまたはワークフローを呼び出すサービス アカウントを選択します。

    新しいサービス アカウントを作成することもできます。

    これにより、トリガーに関連付けられた Identity and Access Management(IAM)サービス アカウントのメールアドレスが設定されます。このメールアドレスには、Eventarc が必要とする特定のロールがすでに付与されています。

  11. [イベントの宛先] リストで、[Workflows] を選択します。
  12. ワークフローを選択します。

    これは、イベントを渡すワークフローの名前です。ワークフロー実行用のイベントは、変換されてランタイム引数としてワークフローに渡されます。

    詳細については、Workflows のトリガーを作成するをご覧ください。

  13. [作成] をクリックします。
  14. トリガーの作成後は、イベントソースのフィルタを変更できません。代わりに、新しいトリガーを作成して古いトリガーを削除します。詳しくは、トリガーの管理をご覧ください。

  1. [作成] をクリックします。

gcloud

トリガーを作成するには、必須フラグとオプションのフラグを指定して gcloud eventarc triggers create コマンドを実行します。

gcloud eventarc triggers create TRIGGER \
  --location=global \
  --destination-workflow=DESTINATION_WORKFLOW  \
  --destination-workflow-location=DESTINATION_WORKFLOW_LOCATION \
  --event-filters="type=EVENT_FILTER_TYPE" \
  --event-filters="COLLECTION_ID=RESOURCE_ID" \
  --event-filters-path-pattern="COLLECTION_ID=PATH_PATTERN" \
  --event-data-content-type="EVENT_DATA_CONTENT_TYPE" \
  --service-account="MY_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com"

Replace the following:

  • TRIGGER: the ID of the trigger or a fully qualified identifier.
  • DESTINATION_WORKFLOW: the ID of the deployed workflow that receives the events from the trigger. The workflow can be in any of the Workflows supported locations and does not need to be in the same location as the trigger. However, the workflow must be in the same project as the trigger.
  • DESTINATION_WORKFLOW_LOCATION (optional): the location in which the destination workflow is deployed. If not specified, it is assumed that the workflow is in the same location as the trigger.
  • EVENT_FILTER_TYPE: the identifier of the event. An event is generated when an API call for the method succeeds. For long-running operations, the event is only generated at the end of the operation, and only if the action is performed successfully. For a list of supported event types, see Event types supported by Eventarc.
  • COLLECTION_ID (optional): the resource component that can act as an event filter, and is one of the following:
    • certificate
    • certificateissuanceconfig
    • certificatemap
    • certificatemapentry
    • dnsauthorization
  • RESOURCE_ID: the identifier of the resource used as the filtering value for the associated collection. For more information, see Resource ID.
  • PATH_PATTERN: the path pattern to apply when filtering for the resource
  • EVENT_DATA_CONTENT_TYPE: (optional) the encoding of the event payload. This can be application/json or application/protobuf. The default encoding is application/json.

    Note that an event payload formatted in JSON is larger than one formatted in Protobuf. This might impact reliability depending on your event destination and its limits on event size. For more information, see Known issues.

  • SERVICE_ACCOUNT_NAME: the name of the IAM service account you created to which you granted specific roles required by Workflows.
  • PROJECT_ID: your Google Cloud project ID

Notes:

  • The --location flag must be global. For more information, see Eventarc locations.
  • The --event-filters="type=EVENT_FILTER_TYPE" flag is required. If no other event filter is set, events for all resources are matched.
  • EVENT_FILTER_TYPE cannot be changed after creation. To change EVENT_FILTER_TYPE, create a new trigger and delete the old one.
  • Each trigger can have multiple event filters, comma delimited in one --event-filters=[ATTRIBUTE=VALUE,...] flag, or you can repeat the flag to add more filters. Only events that match all the filters are sent to the destination. Wildcards and regular expressions are not supported; however, when using the --event-filters-path-pattern flag, you can define a resource path pattern.
  • The --service-account flag is used to specify the Identity and Access Management (IAM) service account email associated with the trigger.

Example:

gcloud eventarc triggers create helloworld-trigger \
  --location=global \
  --destination-workflow=my-workflow \
  --destination-workflow-location=us-central1 \
  --event-filters="type=google.cloud.certificatemanager.certificate.v1.updated" \
  --event-filters-path-pattern="certificate=my-certificate-*" \
  --service-account="${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"

このコマンドは、google.cloud.certificatemanager.certificate.v1.updated として識別されるイベントに helloworld-trigger というトリガーを作成し、my-certificate- で始まる certificate ID のイベントを照合します。