Skip to content

Honeybadger Terraform provider

View Markdown

The Honeybadger Terraform provider lets you manage your Honeybadger configuration as code.

This guide gets you from zero to your first terraform apply. See the provider docs on the Terraform Registry for a full reference of the available resources and attributes.

AreaResources
Projectshoneybadger_project, honeybadger_ingestion_key, honeybadger_environment
Uptime and cron monitoringhoneybadger_site, honeybadger_check_in
Insightshoneybadger_alarm, honeybadger_dashboard
Accesshoneybadger_team
Status pageshoneybadger_status_page
Integrationshoneybadger_integration_<service>, one resource per service

There are 34 integration resources, including Slack, PagerDuty, GitHub, Jira, Linear, Microsoft Teams, Opsgenie, Discord, email, and webhooks. See the Registry docs for a full list.

The provider calls API v3, so it needs an API v3 token. You can use two kinds of tokens:

  • A user API token acts as you. Create one in your user settings.
  • An account API token acts as your account. Create one in your account settings. Use this for CI, so your Terraform runs don’t depend on one person’s access.

The token needs the read and write scopes for each resource it manages. For example, check-ins need checkins:read and checkins:write. Creating a project also needs projects:create. The Registry docs include a list of resources and their scopes.

Export the token as HONEYBADGER_API_TOKEN. The provider reads it from the environment, which keeps it out of your repository:

Terminal window
export HONEYBADGER_API_TOKEN=hbu_your_token

The provider works with Terraform 1.0 or later. This config creates a project, an ingestion key for your app to report with, a check-in for a nightly job, an uptime check, and an email integration that sends the alerts:

main.tf
terraform {
required_providers {
honeybadger = {
source = "honeybadger-io/honeybadger"
version = "~> 0.1"
}
}
}
provider "honeybadger" {
# Reads HONEYBADGER_API_TOKEN from the environment.
}
resource "honeybadger_project" "app" {
name = "My App"
language = "ruby"
}
# The key your app reports errors with.
resource "honeybadger_ingestion_key" "app" {
project_id = honeybadger_project.app.id
label = "production"
}
# Alert when the nightly job doesn't report in.
resource "honeybadger_check_in" "nightly" {
project_id = honeybadger_project.app.id
name = "Nightly billing"
report_period = "1 day"
grace_period = "10 minutes"
}
# Check the health endpoint from two continents.
resource "honeybadger_site" "api" {
project_id = honeybadger_project.app.id
url = "https://api.example.com/health"
locations = ["Virginia", "Frankfurt"]
match_type = "include"
match = "ok"
}
# Email alerts for errors, outages, and missed check-ins.
resource "honeybadger_integration_email" "alerts" {
project_id = honeybadger_project.app.id
config = {
email = "alerts@example.com"
}
}
output "ingestion_key" {
value = honeybadger_ingestion_key.app.key
sensitive = true
}
output "check_in_url" {
value = honeybadger_check_in.nightly.report_url
}

Then install the provider and apply the config:

Terminal window
terraform init
terraform apply

The outputs give you the values your app needs: the ingestion key (your project’s API key) and the URL the nightly job calls to check in. Ingestion key values are marked sensitive, so an output that returns one needs sensitive = true. To read the key, run terraform output -raw ingestion_key.

You can also pass honeybadger_ingestion_key.app.key directly to another resource, such as a secret in your secrets manager, so nobody has to copy the key by hand.

See the provider’s GitHub repository for a working example of every resource.

You don’t have to start from scratch. Every resource supports terraform import, so you can bring your existing Honeybadger resources into Terraform.

With Terraform 1.5 or later, add an import block for each object:

import {
to = honeybadger_project.app
id = "Xk9mZp"
}
import {
to = honeybadger_check_in.nightly
id = "Xk9mZp/b4Ck9w"
}

Projects, teams, and status pages are imported by their ID. Everything else uses <project_id>/<id>. To find the IDs, list the objects with API v3. For example, list your projects or list a project’s check-ins.

If you haven’t written the resource blocks yet, Terraform can write them for you:

Terminal window
terraform plan -generate-config-out=generated.tf

Honeybadger never returns integration credentials, so Terraform can’t read them during an import. Add them to your config, and the terraform apply that imports the resource sets them again.