Have a notification channel defined in your Terraform configuration. For
more information, see the documentation for the google_monitoring_notification_channel
resource.
Example configuration
The following example Terraform configuration enables Personalized Service Health and
alerts for all new incidents and all updates.
provider"google"{project="PROJECT_ID"}resource"google_project_service""project"{service="servicehealth.googleapis.com"}resource"google_monitoring_alert_policy""alert_policy_all"{display_name="All incidents, all updates"combiner="OR"enabled="true"conditions{display_name="test condition"condition_matched_log{filter="resource.type = \"servicehealth.googleapis.com/Event\" AND jsonPayload.category = \"INCIDENT\" AND jsonPayload.@type = \"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\""label_extractors={state="EXTRACT(jsonPayload.state)"description="EXTRACT(jsonPayload.description)"impactedProducts="EXTRACT(jsonPayload.impactedProducts)"startTime="EXTRACT(jsonPayload.startTime)"title="EXTRACT(jsonPayload.title)"impactedLocations="EXTRACT(jsonPayload.impactedLocations)"}}}documentation{content="### $${log.extracted_label.title}\nCheck out [Personalized Service Health dashboard](https://console.cloud.google.com/servicehealth/incidentDetails/projects%2F${resource.labels.resource_container}%2Flocations%2F${resource.labels.location}%2Fevents%2F${resource.labels.event_id}?project=${resource.labels.resource_container}) for more details.<br><br> Description: $${log.extracted_label.description}<br><br> Impacted products: $${log.extracted_label.impactedProducts}<br><br> Impacted locations: $${log.extracted_label.impactedLocations}<br><br> Incident start time: $${log.extracted_label.startTime}<br><br> State: $${log.extracted_label.state}"mime_type="text/markdown"}alert_strategy{notification_rate_limit{period="300s"}}notification_channels=["projects/PROJECT_ID/notificationChannels/NOTIFICATION_CHANNEL"]user_labels={#Addanyextralabelsthatmightbehelpfulscope="all"}}
The service servicehealth.googleapis.com refers to Personalized Service Health, and the
filter pulls all events. See the
Service Health API reference for the fields you can set.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Configure alerts in Terraform\n\nIf you're using Terraform, you can set up alerts for service health events that\nappear in Personalized Service Health. This document explains how.\n\nBefore you begin\n----------------\n\n1. [Enable the Service Health API](/service-health/docs/manage-access#enable-service-health-api-single-project) for the project that you want to create alerts for.\n2. Have a notification channel defined in your Terraform configuration. For more information, see the documentation for the [`google_monitoring_notification_channel`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_notification_channel) resource.\n\nExample configuration\n---------------------\n\nThe following example Terraform configuration enables Personalized Service Health and\nalerts for all new incidents and all updates. \n\n provider \"google\" {\n project = \"\u003cvar scope=\"PROJECT_ID\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\"\n }\n\n resource \"google_project_service\" \"project\" {\n service = \"servicehealth.googleapis.com\"\n }\n\n resource \"google_monitoring_alert_policy\" \"alert_policy_all\" {\n display_name = \"All incidents, all updates\"\n combiner = \"OR\"\n enabled = \"true\"\n conditions {\n display_name = \"test condition\"\n condition_matched_log {\n filter = \"resource.type = \\\"servicehealth.googleapis.com/Event\\\" AND jsonPayload.category = \\\"INCIDENT\\\" AND jsonPayload.@type = \\\"type.googleapis.com/google.cloud.servicehealth.logging.v1.EventLog\\\"\"\n label_extractors = {\n state = \"EXTRACT(jsonPayload.state)\"\n description = \"EXTRACT(jsonPayload.description)\"\n impactedProducts = \"EXTRACT(jsonPayload.impactedProducts)\"\n startTime = \"EXTRACT(jsonPayload.startTime)\"\n title = \"EXTRACT(jsonPayload.title)\"\n impactedLocations = \"EXTRACT(jsonPayload.impactedLocations)\"\n }\n }\n }\n\n documentation {\n content = \"### $${log.extracted_label.title}\\nCheck out [Personalized Service Health dashboard](https://console.cloud.google.com/servicehealth/incidentDetails/projects%2F${resource.labels.resource_container}%2Flocations%2F${resource.labels.location}%2Fevents%2F${resource.labels.event_id}?project=${resource.labels.resource_container}) for more details.\u003cbr\u003e\u003cbr\u003e Description: $${log.extracted_label.description}\u003cbr\u003e\u003cbr\u003e Impacted products: $${log.extracted_label.impactedProducts}\u003cbr\u003e\u003cbr\u003e Impacted locations: $${log.extracted_label.impactedLocations}\u003cbr\u003e\u003cbr\u003e Incident start time: $${log.extracted_label.startTime}\u003cbr\u003e\u003cbr\u003e State: $${log.extracted_label.state}\"\n mime_type = \"text/markdown\"\n }\n alert_strategy {\n notification_rate_limit {\n period = \"300s\"\n }\n }\n\n notification_channels = [\"projects/\u003cvar scope=\"PROJECT_ID\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/notificationChannels/\u003cvar scope=\"NOTIFICATION_CHANNEL\" translate=\"no\"\u003eNOTIFICATION_CHANNEL\u003c/var\u003e\"]\n\n user_labels = { # Add any extra labels that might be helpful\n scope = \"all\"\n }\n }\n\nThe service `servicehealth.googleapis.com` refers to Personalized Service Health, and the\nfilter pulls all events. See the\n[Service Health API reference](/service-health/docs/reference) for the fields you can set.\n\nThe previous configuration is equivalent to choosing the **All incidents, all\nupdates** option in\n[setting up an alert within the Service Health dashboard](/service-health/docs/configure-alerts-dashboard).\n\nSee the following pages for more information on the fields you can set in the\nalert policy:\n\n- Documentation for the [`google_monitoring_alert_policy`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy) resource.\n\n- [Example alert conditions](/service-health/docs/example-alerting-policies#example_alert_conditions)\n that you can add to the `filter` field of your Terraform configuration and\n define when the alert triggers."]]