A service event rule allows you to set actions that should be taken on events for a service that meet the designated rule criteria.
Rulesets and Event Rules will end-of-life soon. We highly recommend that you migrate to Event Orchestration as soon as possible so you can take advantage of the new functionality, such as improved UI, rule creation, REST APIs and Terraform support, advanced conditions, and rule nesting.
resource "pagerduty_service" "example" {
name = "Checkout API Service"
auto_resolve_timeout = 14400
acknowledgement_timeout = 600
escalation_policy = pagerduty_escalation_policy.example.id
alert_creation = "create_alerts_and_incidents"
}
resource "pagerduty_service_event_rule" "foo" {
service = pagerduty_service.example.id
position = 0
disabled = true
conditions {
operator = "and"
subconditions {
operator = "contains"
parameter {
value = "disk space"
path = "summary"
}
}
}
variable {
type = "regex"
name = "Src"
parameters {
value = "(.*)"
path = "source"
}
}
actions {
annotate {
value = "From Terraform"
}
extractions {
target = "dedup_key"
source = "source"
regex = "(.*)"
}
extractions {
target = "summary"
template = "Warning: Disk Space Low on {{Src}}"
}
}
}
resource "pagerduty_service_event_rule" "bar" {
service = pagerduty_service.foo.id
position = 1
disabled = true
conditions {
operator = "and"
subconditions {
operator = "contains"
parameter {
value = "cpu spike"
path = "summary"
}
}
}
actions {
annotate {
value = "From Terraform"
}
}
}
The following arguments are supported:
service
- (Required) The ID of the service that the rule belongs to.conditions
- (Required) Conditions evaluated to check if an event matches this event rule.position
- (Optional) Position/index of the rule within the service.disabled
- (Optional) Indicates whether the rule is disabled and would therefore not be evaluated.time_frame
- (Optional) Settings for scheduling the rule.actions
- (Optional) Actions to apply to an event if the conditions match.variable
- (Optional) Populate variables from event payloads and use those variables in other event actions. NOTE: A rule can have multiple variable
objects.conditions
) supports the following:operator
- Operator to combine sub-conditions. Can be and
or or
.subconditions
- List of sub-conditions that define the condition.subconditions
) supports the following:operator
- Type of operator to apply to the sub-condition. Can be exists
,nexists
,equals
,nequals
,contains
,ncontains
,matches
, or nmatches
.parameter
- Parameter for the sub-condition. It requires both a path
and value
to be set. The path
value must be a PagerDuty Common Event Format (PD-CEF) field.actions
) supports the following:priority
(Optional) - The ID of the priority applied to the event.severity
(Optional) - The severity level of the event. Can be either info
,error
,warning
, or critical
.annotate
(Optional) - Note added to the event.extractions
(Optional) - Allows you to copy important data from one event field to another. Extraction objects may use either of the following field structures:
source
- Field where the data is being copied from. Must be a PagerDuty Common Event Format (PD-CEF) field.target
- Field where the data is being copied to. Must be a PagerDuty Common Event Format (PD-CEF) field.regex
- The conditions that need to be met for the extraction to happen. Must use valid RE2 regular expression syntax.- OR -
template
- A customized field message. This can also include variables extracted from the payload by using string interpolation.target
- Field where the data is being copied to. Must be a PagerDuty Common Event Format (PD-CEF) field.NOTE: A rule can have multiple extraction
objects attributed to it.
suppress
(Optional) - Controls whether an alert is suppressed (does not create an incident).
value
- Boolean value that indicates if the alert should be suppressed before the indicated threshold values are met.threshold_value
- The number of alerts that should be suppressed.threshold_time_amount
- The number value of the threshold_time_unit
before an incident is created.threshold_time_unit
- The seconds
,minutes
, or hours
the threshold_time_amount
should be measured.event_action
(Optional) - An object with a single value
field. The value sets whether the resulting alert status is trigger
or resolve
.suspend
(Optional) - An object with a single value
field. The value sets the length of time to suspend the resulting alert before triggering.name
(Optional) - The name of the variable.type
(Optional) - Type of operation to populate the variable. Usually regex
.parameters
(Optional) - The parameters for performing the operation to populate the variable.
value
- The value for the operation. For example, an RE2 regular expression for regex-type variables.path
- Path to a field in an event, in dot-notation. For Event Rules on a Service, this will have to be a PD-CEF field.time_frame
) supports the following:scheduled_weekly
(Optional) - Values for executing the rule on a recurring schedule.
weekdays
- An integer array representing which days during the week the rule executes. For example weekdays = [1,3,7]
would execute on Monday, Wednesday and Sunday.timezone
- Timezone for the given schedule.start_time
- Time when the schedule will start. Unix timestamp in milliseconds. For example, if you have a rule with a start_time
of 0
and a duration
of 60,000
then that rule would be active from 00:00
to 00:01
. If the start_time
was 3,600,000
the it would be active starting at 01:00
.duration
- Length of time the schedule will be active. Unix timestamp in milliseconds.active_between
(Optional) - Values for executing the rule during a specific time period.
start_time
- Beginning of the scheduled time when the rule should execute. Unix timestamp in milliseconds.end_time
- Ending of the scheduled time when the rule should execute. Unix timestamp in milliseconds.The following attributes are exported:
id
- The ID of the rule.Service event rules can be imported using using the related service
id and the service_event_rule
id separated by a dot, e.g.
$ terraform import pagerduty_service_event_rule.main a19cdca1-3d5e-4b52-bfea-8c8de04da243.19acac92-027a-4ea0-b06c-bbf516519601