使用 Terraform 建立及管理通知管道

Google Cloud Terraform Provider 可讓您在 Google Cloud 專案中建立、編輯及刪除通知管道。通知管道會指定警告政策觸發時,您接收通知的方式。您可以使用 google_monitoring_notification_channel 和 google_monitoring_alert_policy 資源設定通知管道和警告政策。

Terraform 會使用設定檔,建構、變更及版本化執行單一應用程式或整個基礎架構所需的元件。如要進一步瞭解如何使用 Terraform,請參閱 Terraform on Google Cloud 說明文件、Google Cloud Terraform Provider 參考資料,以及開始使用 - Google Cloud。

事前準備

如要取得使用 Terraform 建立及修改通知管道所需的權限,請要求管理員授予您專案的通知管道編輯者 (roles/monitoring.notificationChannelEditor) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

如要進一步瞭解 Cloud Monitoring 角色,請參閱「使用 Identity and Access Management 控管存取權」。

建立通知管道

如要在 Google Cloud 專案中建立通知管道,請按照下列步驟操作:

  1. 安裝及設定 Terraform。

  2. 在 Cloud Shell 中,前往 Terraform 設定所在的目錄。

  3. 編輯設定檔,並新增通知管道。

    舉例來說,下列 google_monitoring_notification_channel 資源設定定義了電子郵件通知管道:

    resource "google_monitoring_notification_channel" "email" {
     display_name = "Tier 1 Support Email"
       type = "email"
       labels = {
         email_address = "USER_EMAIL"
       }
     }
    
  4. 在 Cloud Shell 中輸入 terraform apply。

編輯或刪除通知管道

如要編輯或刪除 Google Cloud 專案中的通知管道,請按照下列步驟操作:

  1. 安裝及設定 Terraform。

  2. 在 Cloud Shell 中,前往 Terraform 設定所在的目錄。

  3. 編輯設定檔,找出通知管道的 google_monitoring_notification_channel 資源,然後修改或刪除該資源。

  4. 在 Cloud Shell 中輸入 terraform apply。

後續步驟