// Why this matters
Good alertmanager pagerduty routing is mostly about what you refuse to page for. Teams that page on every warning learn to ignore pages, and the first real incident arrives into an inbox that has been trained to be skimmed. The rule we use is blunt on purpose: a page needs an explicit opt-in label and critical severity; everything else is a chat message.
The second half of the problem is the opposite failure: alerts that fire and go nowhere. Platforms that onboard teams automatically will, sooner or later, create a service before anyone has decided who should be on call. If the default for an unconfigured service is "nothing happens", you have an outage in your alerting that you will discover during an incident.
Failing safe means picking the default that is annoying rather than invisible. A parked incident on a placeholder policy is annoying in the right way: it shows up in the incident list, it can be searched for, and the runbook says exactly how to fix it.
// The problem
In a multi-tenant platform, alert rules are written by many teams with different ideas of severity. Prometheus evaluates them, Alertmanager groups and routes them, and Grafana has its own alerting engine with contact points. Each needs a destination and a credential, and each is a place where "I thought that went to PagerDuty" can be false.
Credentials are the other pain. PagerDuty Events API integration keys are secrets. If a team has to paste one into a values file, it ends up in Git, in a ticket, or in a screenshot. If a platform engineer has to create each service by clicking, services are inconsistent and some are missing.
We need routing that is explicit and testable, services that exist because teams exist, and a delivery path for keys that never touches a human.
// The solution
The Terraform side is deliberately small. For each team in the platform's team list it creates a pagerduty_service and an events API v2 pagerduty_service_integration, with the escalation policy set to a shared placeholder. The integration key is written to the secret store at a per-team path as part of the same apply. This is the same "team list drives everything" idea as From Form to Running Cluster: Self-Service Team Onboarding, and it keeps services and namespaces from drifting.
The placeholder policy is created once and contains a single rule that notifies a small platform-owned schedule. Its only job is to guarantee that a page is never swallowed. Once the owning team provides real on-call details, an operator attaches the real policy in the PagerDuty UI or via a second Terraform variable; that step is documented because we decided not to automate a decision that needs a human.
On the receiving side, Alertmanager routes by matchers. The top-level route has a child that matches pagerduty="true" and severity="critical" with continue: false, sending to the PagerDuty receiver; a second child sends everything for the team to Slack. Each team gets its own receiver pair, selected by a team label that rules must carry. Grafana-managed alerts use contact points and notification policies with the same two-label logic, so behaviour is identical regardless of which engine fired the alert.
Keys reach both systems through External Secrets: the secret store path becomes a Kubernetes Secret, which the Alertmanager config references through routing_key_file, and which Grafana provisioning reads as an environment variable. Compare the config model in Vault as the Control Plane: A Five-Tier Key Model with Locking. Alternatives we rejected were routing purely on severity (too noisy, no opt-in), one global PagerDuty service (no ownership, no escalation per team) and storing keys in Helm values (leaks into Git).
- Team listthe same source that creates namespaces
- Terraformone PagerDuty service plus integration per team
- Placeholder policynew services land on a parking escalation policy
- Secret storeintegration keys written to a per-team path
- DeliveryExternal Secrets mounts keys for Alertmanager and Grafana
- Gate: route match gatelabels pagerduty=true AND severity=critical
- Pagematched alerts go to the team service
- Chateverything else goes to the team Slack channel
- Manual stepattach the real escalation policy per runbook
- Alert firesPrometheus rule or Grafana rule
- Has team label?no, goes to a platform catch-all channel
- Gate: pagerduty=true and severity=critical gateboth required to page
- Pageteam PagerDuty service via events API
- Otherwiseteam Slack channel
- Escalation policyplaceholder until attached to the real one
// Before you start
- A PagerDuty account with API access and permission to create services and integrations.
- Terraform 1.5+ and the
PagerDuty/pagerdutyprovider. - Prometheus with Alertmanager (or kube-prometheus-stack) and a Grafana instance with unified alerting.
- A secret store (Vault shown) and External Secrets Operator in the cluster.
- A Slack incoming webhook or app token stored as a secret, per team or shared.
- An agreed label contract for alerts:
team,severity,pagerduty.
// Step-by-step implementation
01 Define the label contract
Decide the three labels before writing any config, and write them down where rule authors will see them.
teamselects the destination,severityexpresses urgency andpagerdutyis the explicit opt-in. The reason for the opt-in is human: critical does not mean "wake someone" to everyone.Enforce the contract with a CI check on rule files so a rule without
teamfails the build instead of landing in the catch-all.02 Create the placeholder policy and per-team services in Terraform
The placeholder escalation policy is created once and referenced by every new service. Give it a real, monitored target, such as a platform on-call schedule, so a parked incident does page someone eventually; the point is that it is never empty.
Services take their names from the team list. Use
for_eachon a set so adding a team is additive and removing one is a visible plan.03 Store each integration key in the secret store
Write the key to a per-team path in the same apply. That guarantees a service never exists without its key being available, and removes any human from the transfer. Use the provider's write-only or ephemeral support if your version has it; otherwise accept that the key is in state and protect state accordingly.
Keep the path convention predictable so the delivery layer can template it from the team name.
04 Deliver keys with External Secrets
An ExternalSecret per team pulls the key into a Kubernetes Secret in the monitoring namespace. Alertmanager can read it from a mounted file, which avoids putting it in the rendered config.
Generate these resources from the same team list so there is no per-team hand-editing.
05 Configure Alertmanager routes and receivers
The route tree has the PagerDuty child first with both matchers, then a Slack child per team. Because the PagerDuty child does not set
continue, a paged alert is not also sent to chat unless you add a second route; many teams prefer both, in which case setcontinue: trueon the page route.Mount each team Secret and reference its file with
routing_key_file, which Alertmanager supports for PagerDuty receivers.06 Mirror the logic in Grafana alerting
Grafana-managed rules do not pass through Alertmanager unless you configure it so, which means they need their own contact points and policy. Provision them as files so the behaviour is reviewed like code.
Use the same label matchers so an alert behaves identically whichever engine evaluated it. The integration key comes from an environment variable populated from the same Secret.
07 Write the runbook for the manual step and test the path
Document the single manual action: when a team supplies on-call details, attach the real escalation policy to its service. Include how to find parked incidents (filter on the placeholder policy) so a missed step is discoverable.
Then test with a synthetic alert for each outcome: page, chat, and parked.
amtoolcan show which route an alert will take without firing it.
// How to verify it works
amtool config routes testreturns the receiver named in each comment above for the three label sets.- The synthetic alert creates an incident on the team service and it shows the placeholder escalation policy until the real one is attached.
- Removing the
pagerdutylabel from the same alert sends a Slack message only; no incident is created. kubectl -n monitoring get externalsecretshowsSecretSyncedfor every team.- Searching Git history for the integration key prefix returns nothing.
// Design decisions and trade-offs
- A page requires two labels,
pagerdutyandcritical; anything else goes to chat. Paging is opt-in twice. - PagerDuty services are created from the same team list that creates namespaces, so a team cannot exist without a service.
- New services attach to a placeholder escalation policy that parks incidents instead of dropping them.
- Integration keys travel through the secret store into Alertmanager and Grafana; they never appear in Git or Terraform state outputs.
- The one manual step (attaching a real escalation policy) is a runbook item, not a hidden assumption.
// Pitfalls and lessons learned
- Without
ignore_changeson the escalation policy, the next apply silently reverts a real policy back to the placeholder. - Alertmanager reads
routing_key_fileat config load; rotating the Secret requires a reload (or use a config reloader sidecar) before the new key is used. - Grafana and Prometheus alerts can fire for the same condition; decide which engine owns each alert or you will page twice.
- Label values are strings:
pagerduty: truewithout quotes in rule YAML is a boolean and will not match"true". - An alert missing the
teamlabel falls through to the catch-all. Lint rules in CI, and alert on alerts reaching the catch-all. - PagerDuty events API v2 routing keys are per integration; copying a key between services makes incidents appear in the wrong place.
- If the placeholder schedule has no one on it, the "safe" default silently drops pages again. Monitor that it is staffed.
// Frequently asked questions
How do I route only critical alerts to PagerDuty in Alertmanager?
Add a child route with matchers for severity="critical" and an explicit opt-in label, pointing at a pagerduty_configs receiver; put it before the catch-all route.
Can Terraform manage PagerDuty services and escalation policies?
Yes, the PagerDuty provider has resources for services, integrations, schedules and escalation policies; use ignore_changes where humans own the value.
How do I keep PagerDuty keys out of Git?
Write them from Terraform to a secret store and deliver with External Secrets, referencing them by file path in Alertmanager.
Does Grafana alerting use the same routing as Alertmanager?
It has its own notification policies and contact points, so replicate the same matcher logic in provisioning.
What should happen to alerts from a new, unconfigured team?
They should land on a staffed placeholder policy so an incident exists and is visible, rather than being dropped.
// The outcome
Every team gets a paging path from day one, noisy alerts stop waking people, and a forgotten escalation policy produces a parked incident someone can find instead of a silent gap. The design trades one deliberate manual step for never losing a real page.
// Where to take it next
- Add a meta-alert that fires when anything reaches the catch-all route or the placeholder policy has open incidents.
- Generate team receivers and routes from the team list with a Helm template.
- Connect alerts to agent tooling as described in Agentic SRE: MCP Servers and Workflow Agents for Change and Observability.
- See how teams are created in From Form to Running Cluster: Self-Service Team Onboarding and cleaned up in Demolition in Dependency Order: Safe, Re-runnable Offboarding.