Skip to content

Tensho/terraform-pagerduty-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PagerDuty Service Terraform Module

Terraform module to manage PagerDuty service resource (batteries included).

Usage

Warning

Technical PagerDuty service can't be created without a reference to an escalation policy. Make sure to create an escalation policy before creating a service.

module "example" {
  source  = "Tensho/service/pagerduty"
  version = "1.5.0"

  name                 = "Example"
  description          = "Example service managed by Terraform"
  escalation_policy_id = pagerduty_escalation_policy.example.id

  auto_resolve_timeout    = 3600
  acknowledgement_timeout = 600

  auto_pause_notifications_parameters = {
    enabled = true
    timeout = 120
  }

  alert_grouping_setting = {
    type = "content_based"

    config = {
      time_window = 300
      aggregate   = "all"
      fields      = ["summary"]
    }
  }

  support_hours = {
    type         = "fixed_time_per_day"
    time_zone    = "Europe/London"
    start_time   = "09:00:00"
    end_time     = "17:00:00"
    days_of_week = [1, 2, 3, 4, 5]
  }

  incident_urgency_rule = {
    type = "use_support_hours"

    during_support_hours = {
      type    = "constant"
      urgency = "high"
    }

    outside_support_hours = {
      type    = "constant"
      urgency = "low"
    }
  }

  scheduled_actions = {
    type       = "urgency_change"
    to_urgency = "high"

    at = {
      type = "named_time"
      name = "support_hours_start"
    }
  }
  
  event_orchestration = {
    enable_event_orchestration_for_service = true

    sets = [
      {
        id = "start"

        rules = [
          {
            label = "Suppress morning alerts"

            condition = {
              expression = "now in Mon,Tue,Wed,Thu,Fri,Sat,Sun 06:00:00 to 07:00:00 Europe/London"
            }

            actions = {
              suppress = true
            }
          }
        ]
      }
    ]

    catch_all = {
      actions = {
        route_to = "unrouted"
      }
    }
  }
}

Check out comprehensive examples in examples folder.

Features

Requirements

Name Version
terraform >= 1.7.0
pagerduty ~> 3.26

Providers

Name Version
pagerduty 3.30.1

Modules

No modules.

Resources

Name Type
pagerduty_alert_grouping_setting.default resource
pagerduty_business_service.default resource
pagerduty_event_orchestration_service.default resource
pagerduty_service.default resource
pagerduty_service_dependency.dependent resource
pagerduty_service_dependency.supporting resource
pagerduty_service_integration.cloudwatch resource
pagerduty_service_integration.datadog resource
pagerduty_service_integration.newrelic resource
pagerduty_slack_connection.default resource
pagerduty_vendor.cloudwatch data source
pagerduty_vendor.datadog data source
pagerduty_vendor.newrelic data source

Inputs

Name Description Type Default Required
acknowledgement_timeout PagerDuty service incident acknowledged-to-triggered state change time in seconds. string "null" no
alert_grouping_setting PagerDuty service alert grouping configuration.
object({
type = string,
config = object({
timeout = optional(number, 0),
aggregate = optional(string),
fields = optional(list(string), []),
time_window = optional(number, 0),
})
})
null no
auto_pause_notifications_parameters PagerDuty service transient incident auto pause before triggering (AIOps add-on).
object({
enabled = bool,
timeout = number,
})
{
"enabled": false,
"timeout": null
}
no
auto_resolve_timeout PagerDuty service incident auto resolution time in seconds. string "null" no
business PagerDuty business service vs technical service switch. bool false no
cloudwatch_integration_enabled PagerDuty service AWS CloudWatch integration switch. bool false no
datadog_integration_enabled PagerDuty service DataDog integration switch. bool false no
description PagerDuty service description. string "Managed by Terraform" no
escalation_policy_id PagerDuty service escalation policy ID. string null no
event_orchestration PagerDuty service event orchestration configuration.
object({
enable_event_orchestration_for_service = optional(bool, true)
sets = optional(list(object({
id = string
rules = list(object({
label = optional(string)
condition = optional(object({
expression = string
}))
actions = object({
annotate = optional(string)
escalation_policy_id = optional(string)
priority_id = optional(string)
route_to = optional(string)
suppress = optional(bool)
suspend_seconds = optional(number)
variables = optional(list(object({
name = string
path = string
value = string
type = string
})), [])
extractions = optional(list(object({
target = string
template = optional(string)
source = optional(string)
regex = optional(string)
})), [])
incident_custom_field_updates = optional(list(object({
id = string
value = string
})), [])
automation_action = optional(object({
name = string
url = string
auto_send = optional(bool, false)
trigger_types = optional(list(string), [])
parameters = optional(list(object({
key = string
value = string
})), [])
headers = optional(list(object({
key = string
value = string
})), [])
}))
pagerduty_automation_action = optional(object({
action_id = string
trigger_types = optional(list(string), [])
}))
})
}))
})), [])
catch_all = optional(object({
actions = object({
annotate = optional(string)
escalation_policy_id = optional(string)
priority_id = optional(string)
suppress = optional(bool)
suspend_seconds = optional(number)
pagerduty_automation_action = optional(object({
action_id = string
trigger_types = optional(list(string), [])
}))
})
}))
})
null no
incident_urgency_rule PagerDuty service incident urgency rule.
object({
type = string
urgency = optional(string)
during_support_hours = optional(object({
type = string
urgency = string
}))
outside_support_hours = optional(object({
type = string
urgency = string
}))
})
null no
name PagerDuty service name string n/a yes
newrelic_integration_enabled PagerDuty service NewRelic integration switch. bool false no
point_of_contact PagerDuty business service point fo contact. string null no
scheduled_actions PagerDuty service incident escalation actions related within support hours.
object({
type = optional(string, "urgency_change")
to_urgency = string
at = object({
type = optional(string, "named_time")
name = string
})
})
null no
service_graph PagerDuty service graph components.
object({
dependent_services = optional(list(object({
name = string
id = string
type = string
})))
supporting_services = optional(list(object({
name = string
id = string
type = string
})))
})
{
"dependent_services": [],
"supporting_services": []
}
no
slack_connection PagerDuty service Slack connection configuration.
object({
workspace_id = optional(string), # SLACK_CONNECTION_WORKSPACE_ID env var
channel_id = string,
notification_type = string,
events = list(string)
urgency = optional(string)
priorities = optional(list(string))
})
null no
support_hours PagerDuty service support hours.
object({
type = optional(string, "fixed_time_per_day")
time_zone = string
days_of_week = list(number)
start_time = string
end_time = string
})
null no
team_id PagerDuty business service owner team ID (Business/Enterprise plan). string null no

Outputs

Name Description
cloudwatch_integration_key PagerDuty service CloudWatch integration key.
datadog_integration_key PagerDuty service DataDog integration key.
newrelic_integration_key PagerDuty service NewRelic integration key.
pagerduty_service PagerDuty service.

Contributing

This project uses conventional commits.

Prerequisites

MacOS

brew install pre-commit tfswitch terraform-docs tflint
pre-commit install --install-hooks
tflint --init

Provider Authentication

Consider environment variables management for Terraform provider authentication via .env file, which mise picks up automatically:

PAGERDUTY_SERVICE_REGION=eu
PAGERDUTY_TOKEN=<REDACTED>
PAGERDUTY_USER_TOKEN=$PAGERDUTY_TOKEN
PagerDuty
export PAGERDUTY_SERVICE_REGION=eu
export PAGERDUTY_TOKEN=<REDACTED>
export PAGERDUTY_USER_TOKEN=$PAGERDUTY_TOKEN

Development

Business Service

cd examples/business-service
terraform init
terraform apply
terraform destroy

Technical Service

cd examples/technical-service
terraform init
terraform apply
terraform destroy

Testing

The terraform test command looks for *.tftest.hcl files in both root directory and tests directory.

terraform init
terraform test
terraform test -filter tests/main.tftest.hcl -verbose

About

Terraform module to manage PagerDuty Service resources

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages