Skip to content

Commit

Permalink
feat(pagerduty_slack_connection): add resource to composition
Browse files Browse the repository at this point in the history
  • Loading branch information
Tensho committed Dec 9, 2024
1 parent 6b8665c commit fc6b8a6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ module "example" {
}
```

## Features

* [x] [PagerDuty business service](https://support.pagerduty.com/main/docs/business-services)
* [x] [PagerDuty service alert grouping](https://support.pagerduty.com/main/docs/intelligent-alert-grouping) (AIOps add-on)
* [x] [PagerDuty service graph](https://support.pagerduty.com/main/docs/service-graph)
* [x] [PagerDuty service Slack integration](https://support.pagerduty.com/main/docs/slack-integration-guide)

<!-- BEGIN_TF_DOCS -->
## Requirements

Expand Down Expand Up @@ -99,6 +106,7 @@ No modules.
| [pagerduty_service_integration.cloudwatch](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/resources/service_integration) | resource |
| [pagerduty_service_integration.datadog](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/resources/service_integration) | resource |
| [pagerduty_service_integration.newrelic](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/resources/service_integration) | resource |
| [pagerduty_slack_connection.default](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/resources/slack_connection) | resource |
| [pagerduty_vendor.cloudwatch](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/data-sources/vendor) | data source |
| [pagerduty_vendor.datadog](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/data-sources/vendor) | data source |
| [pagerduty_vendor.newrelic](https://registry.terraform.io/providers/pagerduty/pagerduty/latest/docs/data-sources/vendor) | data source |
Expand All @@ -112,16 +120,17 @@ No modules.
| <a name="input_auto_pause_notifications_parameters"></a> [auto\_pause\_notifications\_parameters](#input\_auto\_pause\_notifications\_parameters) | PagerDuty service transient incident auto pause before triggering (AIOps add-on). | <pre>object({<br/> enabled = bool,<br/> timeout = number,<br/> })</pre> | <pre>{<br/> "enabled": false,<br/> "timeout": null<br/>}</pre> | no |
| <a name="input_auto_resolve_timeout"></a> [auto\_resolve\_timeout](#input\_auto\_resolve\_timeout) | PagerDuty service incident auto resolution time in seconds. | `string` | `"null"` | no |
| <a name="input_business"></a> [business](#input\_business) | PagerDuty business service vs technical service switch. | `bool` | `false` | no |
| <a name="input_cloudwatch_integration_enabled"></a> [cloudwatch\_integration\_enabled](#input\_cloudwatch\_integration\_enabled) | PagerDuty AWS CloudWatch integration switch | `bool` | `false` | no |
| <a name="input_datadog_integration_enabled"></a> [datadog\_integration\_enabled](#input\_datadog\_integration\_enabled) | PagerDuty DataDog integration switch | `bool` | `false` | no |
| <a name="input_cloudwatch_integration_enabled"></a> [cloudwatch\_integration\_enabled](#input\_cloudwatch\_integration\_enabled) | PagerDuty service AWS CloudWatch integration switch. | `bool` | `false` | no |
| <a name="input_datadog_integration_enabled"></a> [datadog\_integration\_enabled](#input\_datadog\_integration\_enabled) | PagerDuty service DataDog integration switch. | `bool` | `false` | no |
| <a name="input_description"></a> [description](#input\_description) | PagerDuty service description. | `string` | `"Managed by Terraform"` | no |
| <a name="input_escalation_policy_id"></a> [escalation\_policy\_id](#input\_escalation\_policy\_id) | PagerDuty service escalation policy ID. | `string` | `null` | no |
| <a name="input_incident_urgency_rule"></a> [incident\_urgency\_rule](#input\_incident\_urgency\_rule) | PagerDuty service incident urgency rule. | <pre>object({<br/> type = string<br/> urgency = optional(string)<br/> during_support_hours = optional(object({<br/> type = string<br/> urgency = string<br/> }))<br/> outside_support_hours = optional(object({<br/> type = string<br/> urgency = string<br/> }))<br/> })</pre> | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | PagerDuty service name | `string` | n/a | yes |
| <a name="input_newrelic_integration_enabled"></a> [newrelic\_integration\_enabled](#input\_newrelic\_integration\_enabled) | PagerDuty NewRelic integration switch | `bool` | `false` | no |
| <a name="input_newrelic_integration_enabled"></a> [newrelic\_integration\_enabled](#input\_newrelic\_integration\_enabled) | PagerDuty service NewRelic integration switch. | `bool` | `false` | no |
| <a name="input_point_of_contact"></a> [point\_of\_contact](#input\_point\_of\_contact) | PagerDuty business service point fo contact. | `string` | `null` | no |
| <a name="input_scheduled_actions"></a> [scheduled\_actions](#input\_scheduled\_actions) | PagerDuty service incident escalation actions related within support hours. | <pre>object({<br/> type = optional(string, "urgency_change")<br/> to_urgency = string<br/> at = object({<br/> type = optional(string, "named_time")<br/> name = string<br/> })<br/> })</pre> | `null` | no |
| <a name="input_service_graph"></a> [service\_graph](#input\_service\_graph) | PagerDuty service graph components. | <pre>object({<br/> dependent_services = optional(list(object({<br/> name = string<br/> id = string<br/> type = string<br/> })))<br/> supporting_services = optional(list(object({<br/> name = string<br/> id = string<br/> type = string<br/> })))<br/> })</pre> | <pre>{<br/> "dependent_services": [],<br/> "supporting_services": []<br/>}</pre> | no |
| <a name="input_slack_connection"></a> [slack\_connection](#input\_slack\_connection) | PagerDuty service Slack connection configuration. | <pre>object({<br/> workspace_id = string,<br/> channel_id = string,<br/> notification_type = string,<br/> events = list(string)<br/> urgency = optional(string)<br/> priorities = optional(list(string))<br/> })</pre> | `null` | no |
| <a name="input_support_hours"></a> [support\_hours](#input\_support\_hours) | PagerDuty service support hours. | <pre>object({<br/> type = optional(string, "fixed_time_per_day")<br/> time_zone = string<br/> days_of_week = list(number)<br/> start_time = string<br/> end_time = string<br/> })</pre> | `null` | no |
| <a name="input_team_id"></a> [team\_id](#input\_team\_id) | PagerDuty business service owner team ID (Business/Enterprise plan). | `string` | `null` | no |

Expand Down
9 changes: 8 additions & 1 deletion examples/technical-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ A basic [PagerDuty technical service](https://support.pagerduty.com/main/docs/se

## Prerequisites

* PagerDuty **escalation policy** resource must exist.
* Export `PAGERDUTY_TOKEN` environment variable with a valid PagerDuty API user token.
* Export `PAGERDUTY_USER_TOKEN` environment variable with a valid PagerDuty API user token.

### Slack Integration

* [Authorise Slack workspace in PagerDuty](https://support.pagerduty.com/main/docs/slack-integration-guide#initial-configuration).
* Replace `workspace_id` parameter with your own Slack workspace ID.
* Replace `channel_id` parameter with your own Slack channel ID.

## Usage

Expand Down
38 changes: 38 additions & 0 deletions examples/technical-service/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#################
# Prerequisites #
#################
data "pagerduty_users" "all" {}

resource "pagerduty_escalation_policy" "example" {
Expand All @@ -13,6 +16,9 @@ resource "pagerduty_escalation_policy" "example" {
}
}

#################
# Target module #
#################
module "example" {
source = "../../"

Expand Down Expand Up @@ -100,8 +106,40 @@ module "example" {
cloudwatch_integration_enabled = true
datadog_integration_enabled = true
newrelic_integration_enabled = true


slack_connection = {
workspace_id = "ABCDEFGHI"
channel_id = "ABCDEFGHIJK"
notification_type = "responder"
events = [
"incident.triggered",
"incident.acknowledged",
"incident.escalated",
"incident.reassigned",
"incident.annotated",
"incident.unacknowledged",
"incident.delegated",
"incident.priority_updated",
"incident.responder.added",
"incident.responder.replied",
"incident.status_update_published",
"incident.reopened",
"incident.action_invocation.created",
"incident.action_invocation.updated",
"incident.action_invocation.terminated",
"incident.role.assigned",
"incident.incident_type.updated",
"incident.resolved",
]
urgency = "high"
priorities = ["*"]
}
}

######################
# Supporting modules #
######################
module "order_api" {
source = "../../"

Expand Down
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,19 @@ resource "pagerduty_service_dependency" "supporting" {
}
}
}

resource "pagerduty_slack_connection" "default" {
count = var.slack_connection != null ? 1 : 0

source_type = "service_reference"
source_id = pagerduty_service.default[0].id
workspace_id = var.slack_connection.workspace_id
channel_id = var.slack_connection.channel_id
notification_type = var.slack_connection.notification_type

config {
events = var.slack_connection.events
urgency = var.slack_connection.urgency
priorities = var.slack_connection.priorities
}
}
6 changes: 6 additions & 0 deletions defaults.tftest.hcl → main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@ run "defaults" {

error_message = "PagerDuty service NewRelic integration is disabled"
}

assert {
condition = length(pagerduty_slack_connection.default) == 0

error_message = "PagerDuty service Slack connection is disabled"
}
}
21 changes: 18 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,32 @@ variable "service_graph" {
variable "cloudwatch_integration_enabled" {
type = bool
default = false
description = "PagerDuty AWS CloudWatch integration switch"
description = "PagerDuty service AWS CloudWatch integration switch."
}

variable "datadog_integration_enabled" {
type = bool
default = false
description = "PagerDuty DataDog integration switch"
description = "PagerDuty service DataDog integration switch."
}

variable "newrelic_integration_enabled" {
type = bool
default = false
description = "PagerDuty NewRelic integration switch"
description = "PagerDuty service NewRelic integration switch."
}

variable "slack_connection" {
type = object({
workspace_id = string,
channel_id = string,
notification_type = string,
events = list(string)
urgency = optional(string)
priorities = optional(list(string))
})
default = null
description = "PagerDuty service Slack connection configuration."

# TODO: Add validations
}

0 comments on commit fc6b8a6

Please sign in to comment.