Skip to content

Commit

Permalink
feat: Create two-level schedule
Browse files Browse the repository at this point in the history
feat: Create two-level schedule
feat: Create PagerDuty Escalation Policy module
feat: Create PagerDuty Service module
feat: Create PagerDuty Escalation Policy module
feat: Create PagerDuty Service module
  • Loading branch information
jai authored Aug 1, 2022
1 parent c3fbfe0 commit 940e510
Show file tree
Hide file tree
Showing 43 changed files with 1,061 additions and 10 deletions.
8 changes: 3 additions & 5 deletions .checkov.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
compact: true
directory:
- gcp-gke
- .
- examples
- modules
download-external-modules: true
evaluate-variables: true
external-modules-download-path: .external_modules
framework:
- all
quiet: true
skip-path:
- .external_modules
- modules
2 changes: 2 additions & 0 deletions .gitguardian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
matches-ignore:
- 3a05c7337c773d81cf59fac4de5c2082abdaf712c229f806fc10aa629bd44022 # Revoked PagerDuty token
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,6 @@ lint/tmp/
!/.idea/runConfigurations/
!/.idea/runConfigurations.xml
/config/quality/lint/report/consumer-lint.html

# GitGuardian
.cache_ggshield
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ repos:
- id: terraform_validate
- id: terraform_tfsec
- id: terraform_checkov
- repo: https://github.com/gitguardian/ggshield
rev: v1.13.0
hooks:
- id: ggshield
language: python
stages: [commit]
args: [ 'secret', 'scan', 'pre-commit' ]
46 changes: 46 additions & 0 deletions examples/honest-two-level-schedule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Honest Two-level PagerDuty Schedule Example

>
> ⚠️ WARNING: This example can only be used to create and destroy. Modifications that result in removal of users
> from the schedule and their destruction will fail due to a mismanaged dependency (PagerDuty tries to destroy the users
> before removing them from the schedule/s).
>
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_pagerduty"></a> [pagerduty](#requirement\_pagerduty) | >= 2.2 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_dummy_users"></a> [dummy\_users](#module\_dummy\_users) | ../../modules/pagerduty-user | n/a |
| <a name="module_schedule"></a> [schedule](#module\_schedule) | ../../modules/honest-two-level-schedule | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_dummy_user_count"></a> [dummy\_user\_count](#input\_dummy\_user\_count) | The number of dummy users to create to place into rotation. | `number` | `2` | no |
| <a name="input_name"></a> [name](#input\_name) | The name to set for the schedule. | `string` | n/a | yes |
| <a name="input_pagerduty_token"></a> [pagerduty\_token](#input\_pagerduty\_token) | PagerDuty API token. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_dummy_user_ids"></a> [dummy\_user\_ids](#output\_dummy\_user\_ids) | The dummy users created to be placed into rotation. |
| <a name="output_level_one_schedule_id"></a> [level\_one\_schedule\_id](#output\_level\_one\_schedule\_id) | n/a |
| <a name="output_level_two_schedule_id"></a> [level\_two\_schedule\_id](#output\_level\_two\_schedule\_id) | n/a |
<!-- END_TF_DOCS -->
1 change: 1 addition & 0 deletions examples/honest-two-level-schedule/example.auto.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "Acquisition Squad"
15 changes: 15 additions & 0 deletions examples/honest-two-level-schedule/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "name" {
description = "The name to set for the schedule."
type = string
}

variable "pagerduty_token" {
type = string
description = "PagerDuty API token."
}

variable "dummy_user_count" {
type = number
default = 2
description = "The number of dummy users to create to place into rotation."
}
24 changes: 24 additions & 0 deletions examples/honest-two-level-schedule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "dummy_users" {
count = var.dummy_user_count

source = "../../modules/pagerduty-user"
name = "pagerduty-schedule-example-user-${count.index}"
email_address = "pagerduty-schedule-example-user-${count.index}@honestbank.com"
}

module "schedule" {
source = "../../modules/honest-two-level-schedule"

name = "Example - ${var.name}"
description = "${var.name} - this is an example description"

# 604,800 seconds = 1 week (7 days)
# 86,400 seconds = 1 day
rotation_turn_length_seconds = 86400

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = module.dummy_users.*.id
}
12 changes: 12 additions & 0 deletions examples/honest-two-level-schedule/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
output "level_one_schedule_id" {
value = module.schedule.level_one_schedule_id
}

output "level_two_schedule_id" {
value = module.schedule.level_two_schedule_id
}

output "dummy_user_ids" {
description = "The dummy users created to be placed into rotation."
value = module.dummy_users.*.id
}
14 changes: 14 additions & 0 deletions examples/honest-two-level-schedule/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
pagerduty = {
source = "pagerduty/pagerduty"
version = ">= 2.2"
}
}

experiments = [module_variable_optional_attrs]
}

provider "pagerduty" {
token = var.pagerduty_token
}
53 changes: 53 additions & 0 deletions examples/pagerduty-escalation-policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# PagerDuty Escalation Policy Example

This example creates a 3-level escalation policy - an example screenshot is provided below:

![img.png](example-escalation-policy-screenshot.png)

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_pagerduty"></a> [pagerduty](#requirement\_pagerduty) | >= 2.2 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_engineering_lead"></a> [engineering\_lead](#module\_engineering\_lead) | ../../modules/pagerduty-user | n/a |
| <a name="module_engineering_user_one"></a> [engineering\_user\_one](#module\_engineering\_user\_one) | ../../modules/pagerduty-user | n/a |
| <a name="module_engineering_user_two"></a> [engineering\_user\_two](#module\_engineering\_user\_two) | ../../modules/pagerduty-user | n/a |
| <a name="module_escalation_policy"></a> [escalation\_policy](#module\_escalation\_policy) | ../../modules/pagerduty-escalation-policy | n/a |
| <a name="module_level_one_engineering_schedule"></a> [level\_one\_engineering\_schedule](#module\_level\_one\_engineering\_schedule) | ../../modules/pagerduty-schedule | n/a |
| <a name="module_level_three_engineering_schedule"></a> [level\_three\_engineering\_schedule](#module\_level\_three\_engineering\_schedule) | ../../modules/pagerduty-schedule | n/a |
| <a name="module_level_three_product_schedule"></a> [level\_three\_product\_schedule](#module\_level\_three\_product\_schedule) | ../../modules/pagerduty-schedule | n/a |
| <a name="module_level_two_engineering_schedule"></a> [level\_two\_engineering\_schedule](#module\_level\_two\_engineering\_schedule) | ../../modules/pagerduty-schedule | n/a |
| <a name="module_level_two_product_schedule"></a> [level\_two\_product\_schedule](#module\_level\_two\_product\_schedule) | ../../modules/pagerduty-schedule | n/a |
| <a name="module_product_lead"></a> [product\_lead](#module\_product\_lead) | ../../modules/pagerduty-user | n/a |
| <a name="module_product_manager"></a> [product\_manager](#module\_product\_manager) | ../../modules/pagerduty-user | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_description"></a> [description](#input\_description) | The description to set for the schedule. | `string` | `"The description to set for the schedule."` | no |
| <a name="input_escalation_delay_in_minutes"></a> [escalation\_delay\_in\_minutes](#input\_escalation\_delay\_in\_minutes) | Minutes until an incident is escalated. | `number` | `60` | no |
| <a name="input_escalation_levels"></a> [escalation\_levels](#input\_escalation\_levels) | Escalation levels and targets | `any` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | The name to set for the schedule. | `string` | `"The name to set for the schedule."` | no |
| <a name="input_pagerduty_token"></a> [pagerduty\_token](#input\_pagerduty\_token) | PagerDuty API token. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | n/a |
<!-- END_TF_DOCS -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/pagerduty-escalation-policy/example.auto.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "example escalation policy"
description = "description of example escalation policy"
26 changes: 26 additions & 0 deletions examples/pagerduty-escalation-policy/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
variable "name" {
default = "example escalation policy name"
description = "The name to set for the schedule."
type = string
}

variable "description" {
default = "example escalation policy description"
description = "The description to set for the schedule."
type = string
}

variable "escalation_delay_in_minutes" {
description = "Minutes until an incident is escalated."
default = 60
}

variable "escalation_levels" {
default = []
description = "Escalation levels and targets"
}

variable "pagerduty_token" {
type = string
description = "PagerDuty API token."
}
130 changes: 130 additions & 0 deletions examples/pagerduty-escalation-policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
module "engineering_user_one" {
source = "../../modules/pagerduty-user"
name = "pagerduty-escalation-policy-example-engineering-user-one"
email_address = "pagerduty-escalation-policy-example-engineering-user-one@honestbank.com"
}

module "engineering_user_two" {
source = "../../modules/pagerduty-user"
name = "pagerduty-escalation-policy-example-engineering-user-two"
email_address = "pagerduty-escalation-policy-example-engineering-user-two@honestbank.com"
}

module "engineering_lead" {
source = "../../modules/pagerduty-user"
name = "pagerduty-escalation-policy-example-engineering-lead"
email_address = "pagerduty-escalation-policy-example-engineering-lead@honestbank.com"
}

module "product_manager" {
source = "../../modules/pagerduty-user"
name = "pagerduty-escalation-policy-example-product-manager"
email_address = "pagerduty-escalation-policy-example-product-manager@honestbank.com"
}

module "product_lead" {
source = "../../modules/pagerduty-user"
name = "pagerduty-escalation-policy-example-product-lead"
email_address = "pagerduty-escalation-policy-example-product-lead@honestbank.com"
}

module "level_one_engineering_schedule" {
source = "../../modules/pagerduty-schedule"

description = "level one engineering schedule"
name = "level one engineering schedule"

# 604,800 seconds = 1 week (7 days)
rotation_turn_length_seconds = 604800

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = [
module.engineering_user_one.id,
module.engineering_user_two.id,
]
}

module "level_two_engineering_schedule" {
source = "../../modules/pagerduty-schedule"

description = "level two engineering schedule"
name = "level two engineering schedule"

# 604,800 seconds = 1 week (7 days)
rotation_turn_length_seconds = 604800

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = [
module.engineering_user_two.id,
module.engineering_user_one.id,
]
}

module "level_two_product_schedule" {
source = "../../modules/pagerduty-schedule"

description = "level two product schedule"
name = "level two product schedule"

# 604,800 seconds = 1 week (7 days)
rotation_turn_length_seconds = 604800

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = [module.product_manager.id]
}

module "level_three_engineering_schedule" {
source = "../../modules/pagerduty-schedule"

description = "level three engineering schedule"
name = "level three engineering schedule"

# 604,800 seconds = 1 week (7 days)
rotation_turn_length_seconds = 604800

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = [module.engineering_lead.id]
}

module "level_three_product_schedule" {
source = "../../modules/pagerduty-schedule"

description = "level three product schedule"
name = "level three product schedule"

# 604,800 seconds = 1 week (7 days)
rotation_turn_length_seconds = 604800

# Wednesday 5pm GMT+7 rotation handover
start_datetime = "2022-07-27T17:00:00+07:00"
time_zone = "Asia/Bangkok"

user_ids = [module.product_lead.id]
}

module "escalation_policy" {
source = "../../modules/pagerduty-escalation-policy"

name = var.name
description = var.description

escalation_delay_in_minutes = 60

escalation_levels = (length(var.escalation_levels) > 0 ? var.escalation_levels : [
[module.level_one_engineering_schedule.id],
[module.level_two_engineering_schedule.id, module.level_two_product_schedule.id],
[module.level_three_engineering_schedule.id, module.level_three_product_schedule.id],
])
}
3 changes: 3 additions & 0 deletions examples/pagerduty-escalation-policy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "id" {
value = module.escalation_policy.id
}
14 changes: 14 additions & 0 deletions examples/pagerduty-escalation-policy/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
pagerduty = {
source = "pagerduty/pagerduty"
version = ">= 2.2"
}
}

experiments = [module_variable_optional_attrs]
}

provider "pagerduty" {
token = var.pagerduty_token
}
Loading

0 comments on commit 940e510

Please sign in to comment.