Managing PagerDuty Business Services With Terraform
By jjm
This is my third blog post about PagerDuty, and the second about using the Terraform provider for PagerDuty. This time I’ll be focusing on business services.
So far I’ve not a chance to make use of business services, but I have spent quite sometime investigating and creating custom tooling using the APIs following the release in early 2020 (which was before I started on my Terraform journey). I can see how business services would be very useful when widely adopted and combined with status pages, which don’t have APIs yet 😢.
While, only the following is the bare minimum needed to create a business_service:
resource "pagerduty_business_service" "blog" {
name = "Geeky and Blonde Blog"
}
Adding extra information, like the team that owns the service, a description and point of contact could help reduce the need to reference external sources (e.g. a Wiki) to PagerDuty during an incident:
resource "pagerduty_business_service" "blog" {
name = "Geeky and Blonde Blog"
description = "The things that make up my blog!"
point_of_contact = "PagerDuty Admin"
team = pagerduty_team.admins.id
}
In the above example, the PagerDuty team that owns the business server was created via IaC, so that it’s possible to reference the team ID without needing to look up and hard code the ID:
resource "pagerduty_team" "admins" {
name = "PD Admins"
}
data "pagerduty_user" "me" {
email = "me@example.com"
}
resource "pagerduty_team_membership" "admins_me" {
team_id = pagerduty_team.admins.id
user_id = data.pagerduty_user.me.id
role = "manager" # Optional, but this is the default.
}
After these have been added, it’s possible to add associations between the business service and the technical services that was added in the previous post (or any other business / technical services):
resource "pagerduty_service_dependency" "biz_blog_2_tech_blog" {
dependency {
dependent_service {
id = pagerduty_business_service.blog.id
type = "business_service"
}
supporting_service {
id = pagerduty_service.blog.id
type = "service"
}
}
}
These service dependencies also don’t just apply for business services they can also be between business services or technical services. I think it would be very interesting to use this information to generate a graph of the dependencies of between all business & technical services in PagerDuty.