本文說明如何使用Google Cloud Terraform Provider 在 Google Cloud 專案中建立通知管道。 Google Cloud Terraform 供應商 提供下列快訊政策和通知管道資源:
Terraform 是一種工具,可建構、變更基礎架構,並管理基礎架構版本。並使用設定檔描述執行單一應用程式或整個基礎架構所需的元件。如要進一步瞭解如何使用 Terraform,請參閱下列資源:
事前準備
如要取得必要權限,以便使用 Terraform 建立及修改通知管道,請要求管理員授予您專案的通知管道編輯者 (roles/monitoring.notificationChannelEditor
) 身分與存取權管理角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
如要進一步瞭解 Cloud Monitoring 角色,請參閱「使用 Identity and Access Management 控制存取權」。
建立通知管道
如要在 Google Cloud 專案中建立通知管道,請按照下列步驟操作:
在 Cloud Shell 中,前往包含 Terraform 設定的目錄。
編輯設定檔,並新增通知管道。
舉例來說,下列設定會定義電子郵件通知管道:
resource "google_monitoring_notification_channel" "email" { display_name = "Tier 1 Support Email" type = "email" labels = { email_address = "USER_EMAIL" } }
在 Cloud Shell 中輸入
terraform apply
。
編輯或刪除通知管道
如要編輯或刪除 Google Cloud 專案中的通知管道,請按照下列步驟操作:
在 Cloud Shell 中,前往包含 Terraform 設定的目錄。
編輯設定檔,找出通知管道的
google_monitoring_notification_channel
資源,然後修改或刪除該資源。在 Cloud Shell 中輸入
terraform apply
。
後續步驟
- 使用 Terraform 建立快訊政策。
- 進一步瞭解 Terraform。
- 試用使用Google Cloud Terraform Provider 和 Cloud Monitoring 的程式碼範例。
- 在 GitHub 上查看 Google Cloud Terraform 供應商存放區。
- 如要回報錯誤或詢問 Terraform 相關問題,請在 GitHub 上提出問題。