Skip to content

Instantly share code, notes, and snippets.

@tratnayake
Created July 22, 2023 23:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
pd_terraform_example_new
locals {
my_team_subteam_a_members = toset([
pagerduty_user.thilina_ratnayake.id,
pagerduty_user.teammate_b.id,
pagerduty_user.teammate_c.id,
])
my_team_subteam_b_members = toset([
pagerduty_user.teammate_a.id,
pagerduty_user.teammate_d.id
])
}
resource "pagerduty_schedule" "myteam_schedule" {
name = "My Team"
time_zone = "America/Los_Angeles"
description = "PD Schedule for My Team, Slack #my-team, Email: my-team@company.com"
layer {
name = "weekday"
rotation_turn_length_seconds = 1209600
rotation_virtual_start = "2023-01-1T09:00:00-08:00"
start = "2023-01-1T09:00:00-08:00"
users = setunion(local.my_team_subteam_a_members, local.my_team_subteam_b_members)
}
}
resource "pagerduty_escalation_policy" "myteam_escalation" {
name = "My Team's escalation policy for all services owned by My-Team"
num_loops = 9
# First Notify
rule {
target {
type = "schedule_reference"
id = pagerduty_schedule.myteam_schedule.id
}
escalation_delay_in_minutes = 10 # How long to wait before escalating
}
# Escalate if not ack'd
rule {
target {
type = "schedule_reference"
id = pagerduty_schedule.otherteam_schedule.id
}
}
}
resource "pagerduty_service" "my_service_prod" {
name = "My-Service PROD"
escalation_policy = pagerduty_escalation_policy.myteam_escalation.id
}
resource "pagerduty_team_membership" "my_team_subteam_a_members" {
for_each = local.my_team_subteam_a_members
user_id = each.value
team_id = pagerduty_team.my_team_subteam_a.id
}
resource "pagerduty_team_membership" "my_team_subteam_b_members" {
for_each = local.my_team_subteam_b_members
user_id = each.value
team_id = pagerduty_team.my_team_subteam_b.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment