Google Cloud (Stackdriver) Monitoring Notification Channel

This page shows how to write Terraform for Cloud (Stackdriver) Monitoring Notification Channel and write them securely.

google_monitoring_notification_channel (Terraform)

The Notification Channel in Cloud (Stackdriver) Monitoring can be configured in Terraform with the resource name google_monitoring_notification_channel. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L21
resource "google_monitoring_notification_channel" "email" {
  count        = var.notification_group_email != "" ? 1 : 0
  project      = var.project
  display_name = var.notification_name
  type         = "email"
  labels = {
notification.tf#L7
resource "google_monitoring_notification_channel" "email" {
  count        = local.is_email ? 1 : 0
  display_name = var.display_name
  type         = var.notification_type
  labels = {
    email_address = var.email_address
monitoringandalerting.tf#L22
resource "google_monitoring_notification_channel" "slack" {
  display_name = "Test Slack Channel"
  type         = "slack"
  labels = {
    "channel_name" = "#tf-gitops-channel"
  }

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

An optional human-readable description of this notification channel. This description may provide additional details, beyond the display name, for the channel. This may not exceed 1024 Unicode characters.

An optional human-readable name for this notification channel. It is recommended that you specify a non-empty and unique name in order to make it easier to identify the channels in your project, though this is not enforced. The display name is limited to 512 Unicode characters.

Whether notifications are forwarded to the described channel. This makes it possible to disable delivery of notifications to a particular channel without removing the channel from all alerting policies that reference the channel. This is a more convenient approach when the change is temporary and you want to receive notifications from the same set of alerting policies on the channel at some point in the future.

  • id optional computed - string
  • labels optional - map from string to string

Configuration fields that define the channel and its behavior. The permissible and required labels are specified in the NotificationChannelDescriptor corresponding to the type field. Labels with sensitive data are obfuscated by the API and therefore Terraform cannot determine if there are upstream changes to these fields. They can also be configured via the sensitive_labels block, but cannot be configured in both places.

  • name optional computed - string

The full REST resource name for this channel. The syntax is: projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID] The [CHANNEL_ID] is automatically assigned by the server on creation.

The type of the notification channel. This field matches the value of the NotificationChannelDescriptor.type field. See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannelDescriptors/list to get the list of valid values such as "email", "slack", etc...

User-supplied key/value data that does not need to conform to the corresponding NotificationChannelDescriptor's schema, unlike the labels field. This field is intended to be used for organizing and identifying the NotificationChannel objects.The field can contain up to 64 entries. Each key and value is limited to 63 Unicode characters or 128 bytes, whichever is smaller. Labels and values can contain only lowercase letters, numerals, underscores, and dashes. Keys must begin with a letter.

Indicates whether this channel has been verified or not. On a ListNotificationChannels or GetNotificationChannel operation, this field is expected to be populated.If the value is UNVERIFIED, then it indicates that the channel is non-functioning (it both requires verification and lacks verification); otherwise, it is assumed that the channel works.If the channel is neither VERIFIED nor UNVERIFIED, it implies that the channel is of a type that does not require verification or that this specific channel has been exempted from verification because it was created prior to verification being required for channels of this type.This field cannot be modified using a standard UpdateNotificationChannel operation. To change the value of this field, you must call VerifyNotificationChannel.

  • sensitive_labels list block

    An authorization token for a notification channel. Channel types that support this field include: slack

    An password for a notification channel. Channel types that support this field include: webhook_basicauth

    An servicekey token for a notification channel. Channel types that support this field include: pagerduty

  • timeouts single block

Explanation in Terraform Registry

A NotificationChannel is a medium through which an alert is delivered when a policy violation is detected. Examples of channels include email, SMS, and third-party messaging applications. Fields containing sensitive information like authentication tokens or contact info are only partially populated on retrieval. Notification Channels are designed to be flexible and are made up of a supported type and labels to configure that channel. Each type has specific labels that need to be present for that channel to be correctly configured. The labels that are required to be present for one channel type are often different than those required for another. Due to these loose constraints it's often best to set up a channel through the UI and import to Terraform when setting up a brand new channel type to determine which labels are required. A list of supported channels per project the list endpoint can be accessed programmatically or through the api explorer at https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannelDescriptors/list . This provides the channel type and all of the required labels that must be passed. To get more information about NotificationChannel, see:

Frequently asked questions

What is Google Cloud (Stackdriver) Monitoring Notification Channel?

Google Cloud (Stackdriver) Monitoring Notification Channel is a resource for Cloud (Stackdriver) Monitoring of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud (Stackdriver) Monitoring Notification Channel?

For Terraform, the jjmartres/terraform, vamshikrishna833/t and EmanuelBurgess/eburgess-gitops-demo source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.