The Simplest Way to Make OpenTofu and Pagerduty Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair opentofu and pagerduty to manage on-call schedules and alert routes as code. This setup lets teams review and apply alert rules alongside cloud servers and apps. Manual changes in an incident tool often break during a real outage. When a new app goes live, someone might forget to add an alert route. Defining alert teams in code stops this gap before it hurts your uptime. Every new service gets an owner and an escalation path on day one. How opentofu and pagerduty share keys and data

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair opentofu and pagerduty to manage on-call schedules and alert routes as code. This setup lets teams review and apply alert rules alongside cloud servers and apps.

Manual changes in an incident tool often break during a real outage. When a new app goes live, someone might forget to add an alert route. Defining alert teams in code stops this gap before it hurts your uptime. Every new service gets an owner and an escalation path on day one.

How opentofu and pagerduty share keys and data

OpenTofu talks to the PagerDuty API using a provider plugin during each run. You give the plugin an API key so it can read and write records. During a plan step, OpenTofu checks your code against the live PagerDuty state. It reads current teams, users, schedules, and service rules over a secure web link.

During an apply step, OpenTofu sends updates to match your desired state. It creates new services, links escalation policies, and outputs routing keys for your monitoring tools. You store these state records in a shared backend so your team stays in sync. You should lock the state file during runs so two people cannot clash.

Notice that your state file can hold sensitive values like webhook URLs and integration keys. You must encrypt this remote state store and restrict who can read it. You should also mask sensitive fields like emails or phone numbers in build logs. Masking rewrites matched fields in results so contact details stay out of plain view.

Common failure modes and how to scope roles

The biggest mistake teams make is sharing one global admin key across all projects. If that single key leaks, an attacker can delete every schedule and silence all alerts. Shared service accounts also hide who made a change in your audit logs. When a bad run wipes out an on-call rotation, you cannot trace the root cause.

Broad keys also create blast radius issues when one team edits another team's rules. A developer might change a shared variable and break alerts for the database group. Unlogged runs from developer laptops make this drift even worse. Someone runs a local apply with old code and overwrites an urgent hotfix.

End-to-End Encryption + PagerDuty Integration Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, split your state files by team or by service boundary. Give each build pipeline a scoped key that only touches its own team resources. Block local runs from laptops and force all changes through a central build runner. Pull keys from a secret store at run time instead of saving them in files. Rotate these API keys on a set schedule to limit exposure.

Keeping manual schedule edits from breaking code runs

Incident tools have a unique problem because humans must trade shifts during the week. If you manage every single shift swap in code, your team will hate the process. And if people swap shifts in the web app, the next code run will undo it.

The best fix is to split base rules from daily human edits. Use OpenTofu to build the services, teams, escalation chains, and blank schedule shells. Let engineers manage their daily shift overrides directly inside the PagerDuty web app. You can tell OpenTofu to ignore changes to rotation member lists after creation. This separation keeps your core alert wiring safe while giving on-call staff flexible control.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should we manage user accounts and contact details in OpenTofu?

Create base user records in code or sync them from your identity provider. Let each person set up their own phone numbers and push alert rules in the app.

How do we pass PagerDuty routing keys to our monitoring tools?

OpenTofu reads the new integration key after it creates a PagerDuty service. You can pass that output value right into your monitoring provider in the same run.

What happens if someone deletes an escalation policy in the web app?

OpenTofu spots the missing policy during the next plan check against the API. Running an apply step will recreate the policy and link it back to your services.

The query runs. The emails stay hidden.