Workflows에 인증서 관리자 이벤트 라우팅

Eventarc 트리거는 특정 이벤트 또는 이벤트 집합에 관심이 있음을 선언합니다. 이벤트 소스나 대상 서비스 등의 트리거 필터를 지정하여 이벤트 라우팅을 구성할 수 있습니다.

이벤트는 HTTP 요청을 통해 CloudEvents 형식으로 전달됩니다. Workflows 서비스는 이벤트를 JSON 객체(CloudEvents 사양에 따름)로 변환하고 이벤트를 워크플로 실행에 워크플로 런타임 인수로 전달합니다. 이벤트 크기가 512KB를 초과하지 않도록 유의하세요. 이벤트가 최대 Workflows 인수 크기보다 큰 경우 워크플로 실행이 트리거되지 않습니다.

이 안내에서는 직접Certificate Manager 이벤트에 대한 응답으로 워크플로 실행이 트리거되도록 이벤트 라우팅을 구성하는 방법을 보여줍니다. 자세한 내용은 지원되는 직접 이벤트 목록을 참조하세요.

트리거 만들기 준비

대상 워크플로에 대한 Eventarc 트리거를 만들기 전에 다음 작업을 완료해야 합니다.

콘솔

  1. Google Cloud 콘솔의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 만들거나 선택합니다.

    프로젝트 선택자로 이동

  2. Eventarc, Eventarc Publishing, Workflows, 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, Eventarc Publishing, Workflows, 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 대상의 역할 및 권한을 참조하세요.

트리거 만들기

Google Cloud CLI(gcloud 또는 Terraform)를 사용하거나 Google Cloud 콘솔을 통해 배포된 워크플로를 이벤트 수신자로 사용하여 Eventarc 트리거를 만들 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 Eventarc 트리거 페이지로 이동합니다.

    트리거로 이동

  2. 트리거 만들기를 클릭합니다.
  3. 트리거 이름을 입력합니다.

    트리거의 ID이며 문자로 시작해야 합니다. 최대 63자(영문 기준)의 소문자, 숫자, 하이픈을 포함할 수 있습니다.

  4. 트리거 유형으로 Google 소스를 선택합니다.
  5. 이벤트 제공자 목록에서 Certificate Manager를 선택합니다.

    연결된 Google Cloud 문서에 사용된 이벤트 제공자 이름에 Cloud 또는 Google Cloud 프리픽스가 없을 수 있습니다. 예를 들어 콘솔에서는 Redis용 MemorystoreRedis용 Google Cloud Memorystore라고 합니다.

  6. 이벤트 유형 목록의 직접 이벤트에서 이벤트 유형을 선택합니다.
  7. 이벤트 페이로드의 인코딩을 지정하려면 이벤트 데이터 콘텐츠 유형 목록에서 application/json 또는 application/protobuf를 선택합니다.

    JSON으로 형식이 지정된 이벤트 페이로드는 Protobuf로 형식이 지정된 이벤트 페이로드보다 큽니다. 그로 인해 이벤트 대상 및 이벤트 크기 한도에 따라 안정성에 영향을 미칠 수 있습니다. 자세한 내용은 알려진 문제를 참조하세요.

  8. 리전 목록에서 전역(전역)을 선택합니다.

    자세한 내용은 Eventarc 위치를 참조하세요.

  9. 이벤트 제공자에 해당하는 경우 필터 추가를 클릭하고 다음을 지정합니다.
    1. 속성 1 필드에서 선택한 직접 이벤트에 따라 이벤트 필터 역할을 할 수 있는 리소스 ID를 선택합니다.
    2. 연산자를 선택합니다.
    3. 속성 값 1 필드에서 선택한 연산자에 따라 정확한 값을 입력하거나 경로 패턴을 적용합니다.
    4. 더 많은 속성 필터를 적용할 수 있으면 필터 추가를 클릭하고 적합한 값을 지정합니다.
  10. 서비스 또는 워크플로를 호출할 서비스 계정을 선택합니다.

    또는 새 서비스 계정을 만들 수 있습니다.

    이는 트리거와 연결되어 있고 이전에 Eventarc에 필요한 특정 역할을 부여한 Identity and Access Management(IAM) 서비스 계정 이메일을 지정합니다.

  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의 이벤트와 일치합니다.