pagerduty_event_orchestration_service

A Service Orchestration allows you to create a set of Event Rules. The Service Orchestration evaluates Events sent to this Service against each of its rules, beginning with the rules in the "start" set. When a matching rule is found, it can modify and enhance the event and can route the event to another set of rules within this Service Orchestration for further processing.

Example of configuring a Service Orchestration

This example shows creating Team, User, Escalation Policy, and Service resources followed by creating a Service Orchestration to handle Events sent to that Service.

This example also shows using priority data source to configure priority action for a rule. If the Event matches the first rule in set "step-two" the resulting incident will have the Priority P1.

This example shows a Service Orchestration that has nested sets: a rule in the "start" set has a route_to action pointing at the "step-two" set.

The catch_all actions will be applied if an Event reaches the end of any set without matching any rules in that set. In this example the catch_all doesn't have any actions so it'll leave events as-is.

resource "pagerduty_team" "engineering" {
  name = "Engineering"
}

resource "pagerduty_user" "example" {
  name  = "Earline Greenholt"
  email = "125.greenholt.earline@graham.name"
}

resource "pagerduty_team_membership" "foo" {
  user_id = pagerduty_user.example.id
  team_id = pagerduty_team.engineering.id
  role    = "manager"
}

resource "pagerduty_escalation_policy" "example" {
  name      = "Engineering Escalation Policy"
  num_loops = 2

  rule {
    escalation_delay_in_minutes = 10
    target {
      type = "user_reference"
      id   = pagerduty_user.example.id
    }
  }
}

resource "pagerduty_service" "example" {
  name                    = "My Web App"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600
  escalation_policy       = pagerduty_escalation_policy.example.id
  alert_creation          = "create_alerts_and_incidents"
}

resource "pagerduty_incident_custom_field" "cs_impact" {
  name       = "impact"
  data_type  = "string"
  field_type = "single_value"
}

data "pagerduty_priority" "p1" {
  name = "P1"
}

resource "pagerduty_event_orchestration_service" "www" {
  service = pagerduty_service.example.id
  enable_event_orchestration_for_service = true
  set {
    id = "start"
    rule {
      label = "Always apply some consistent event transformations to all events"
      actions {
        variable {
          name = "hostname"
          path = "event.component"
          value = "hostname: (.*)"
          type = "regex"
        }
        extraction {
          # Demonstrating a template-style extraction
          template = "{{variables.hostname}}"
          target = "event.custom_details.hostname"
        }
        extraction {
          # Demonstrating a regex-style extraction
          source = "event.source"
          regex = "www (.*) service"
          target = "event.source"
        }
        # Id of the next set
        route_to = "step-two"
      }
    }
  }
  set {
    id = "step-two"
    rule {
      label = "All critical alerts should be treated as P1 incident"
      condition {
        expression = "event.severity matches 'critical'"
      }
      actions {
        annotate = "Please use our P1 runbook: https://docs.test/p1-runbook"
        priority = data.pagerduty_priority.p1.id
        incident_custom_field_update {
          id = pagerduty_incident_custom_field.cs_impact.id
          value = "High Impact"
        }
      }
    }
    rule {
      label = "If there's something wrong on the canary let the team know about it in our deployments Slack channel"
      condition {
        expression = "event.custom_details.hostname matches part 'canary'"
      }
      # create webhook action with parameters and headers
      actions {
        automation_action {
          name = "Canary Slack Notification"
          url = "https://our-slack-listerner.test/canary-notification"
          auto_send = true
          parameter {
            key = "channel"
            value = "#my-team-channel"
          }
          parameter {
            key = "message"
            value = "something is wrong with the canary deployment"
          }
          header {
            key = "X-Notification-Source"
            value = "PagerDuty Incident Webhook"
          }
        }
      }
    }
    rule {
      label = "Never bother the on-call for info-level events outside of work hours"
      condition {
        expression = "event.severity matches 'info' and not (now in Mon,Tue,Wed,Thu,Fri 09:00:00 to 17:00:00 America/Los_Angeles)"
      }
      actions {
        suppress = true
      }
    }
  }
  catch_all {
    actions { }
  }
}

Argument Reference

The following arguments are supported:

Set (set) supports the following:

Rule (rule) supports the following:

Condition (condition) supports the following:

Actions (actions) supports the following:

Catch All (catch_all) supports the following:

Attributes Reference

The following attributes are exported:

Import

Service Orchestration can be imported using the id of the Service, e.g.

$ terraform import pagerduty_event_orchestration_service.service PFEODA7