Create and manage notification channels with Terraform

The Google Cloud Terraform Provider lets you create, edit, and delete notification channels in your Google Cloud project. Notification channels specify how you receive notifications when alerting policies trigger. You configure notification channels and alerting policies by using the google_monitoring_notification_channel and google_monitoring_alert_policy resources.

Terraform uses configuration files to build, change, and version the components needed to run a single application or your entire infrastructure. For more information about using Terraform, see the Terraform on Google Cloud documentation, the Google Cloud Terraform Provider reference, and Get Started - Google Cloud.

Before you begin

To get the permissions that you need to create and modify notification channels by using Terraform, ask your administrator to grant you the Notification Channel Editor (roles/monitoring.notificationChannelEditor) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

For more information about Cloud Monitoring roles, see Control access with Identity and Access Management.

Create a notification channel

To create a notification channel in your Google Cloud project, do the following:

  1. Install and configure Terraform.

  2. In the Cloud Shell, go to the directory that contains your Terraform configuration.

  3. Edit the configuration file and add your notification channel.

    For example, the following configuration of the google_monitoring_notification_channel resource defines an email notification channel:

    resource "google_monitoring_notification_channel" "email" {
     display_name = "Tier 1 Support Email"
       type = "email"
       labels = {
         email_address = "USER_EMAIL"
       }
     }
    
  4. In the Cloud Shell, enter terraform apply.

Edit or delete notification channels

To edit or delete a notification channel in your Google Cloud project, do the following:

  1. Install and configure Terraform.

  2. In the Cloud Shell, go to the directory that contains your Terraform configuration.

  3. Edit your configuration file, find the google_monitoring_notification_channel resource for your notification channel, and then modify or delete that resource.

  4. In the Cloud Shell, enter terraform apply.

What's next