Skip to content

Commit 1abf888

Browse files
authored
Add notify_next_on_call_from_schedule escalation type (#2645)
* Add notify_next_on_call_from_schedule escalation type Support the newly exposed STEP_NOTIFY_SCHEDULE_NEXT public API step (notify_next_on_call_from_schedule) in the grafana_oncall_escalation resource. This type notifies the next person on-call from a schedule rather than the current one, and reuses the existing notify_on_call_from_schedule field to reference the schedule ID.
1 parent 45c089d commit 1abf888

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

docs/resources/oncall_escalation.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ resource "grafana_oncall_escalation" "example_notify_step" {
5151
]
5252
position = 0
5353
}
54+
55+
// Notify next on-call from schedule step
56+
resource "grafana_oncall_escalation" "example_notify_next_on_call_step" {
57+
escalation_chain_id = grafana_oncall_escalation_chain.default.id
58+
type = "notify_next_on_call_from_schedule"
59+
notify_on_call_from_schedule = grafana_oncall_schedule.example_schedule.id
60+
position = 1
61+
}
5462
```
5563

5664
<!-- schema generated by tfplugindocs -->
@@ -60,17 +68,17 @@ resource "grafana_oncall_escalation" "example_notify_step" {
6068

6169
- `escalation_chain_id` (String) The ID of the escalation chain.
6270
- `position` (Number) The position of the escalation step (starts from 0).
63-
- `type` (String) The type of escalation policy. Can be wait, notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, trigger_webhook, notify_user_group, resolve, notify_whole_channel, notify_if_time_from_to, notify_if_num_alerts_in_window, repeat_escalation, notify_team_members, declare_incident
71+
- `type` (String) The type of escalation policy. Can be wait, notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, notify_next_on_call_from_schedule, trigger_webhook, notify_user_group, resolve, notify_whole_channel, notify_if_time_from_to, notify_if_num_alerts_in_window, repeat_escalation, notify_team_members, declare_incident
6472

6573
### Optional
6674

6775
- `action_to_trigger` (String) The ID of an Action for trigger_webhook type step.
6876
- `duration` (Number) The duration of delay for wait type step. (60-86400) seconds
6977
- `group_to_notify` (String) The ID of a User Group for notify_user_group type step.
70-
- `important` (Boolean) Will activate "important" personal notification rules. Actual for steps: notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, notify_user_group and notify_team_members
78+
- `important` (Boolean) Will activate "important" personal notification rules. Actual for steps: notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, notify_next_on_call_from_schedule, notify_user_group and notify_team_members
7179
- `notify_if_time_from` (String) The beginning of the time interval for notify_if_time_from_to type step in UTC (for example 08:00:00Z).
7280
- `notify_if_time_to` (String) The end of the time interval for notify_if_time_from_to type step in UTC (for example 18:00:00Z).
73-
- `notify_on_call_from_schedule` (String) ID of a Schedule for notify_on_call_from_schedule type step.
81+
- `notify_on_call_from_schedule` (String) ID of a Schedule for notify_on_call_from_schedule or notify_next_on_call_from_schedule type step.
7482
- `notify_to_team_members` (String) The ID of a Team for a notify_team_members type step.
7583
- `num_alerts_in_window` (Number) Number of alerts that must occur within the time window to continue escalation for notify_if_num_alerts_in_window type step.
7684
- `num_minutes_in_window` (Number) Time window in minutes to count alerts for notify_if_num_alerts_in_window type step.

examples/resources/grafana_oncall_escalation/resource.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ resource "grafana_oncall_escalation" "example_notify_step" {
3535
]
3636
position = 0
3737
}
38+
39+
// Notify next on-call from schedule step
40+
resource "grafana_oncall_escalation" "example_notify_next_on_call_step" {
41+
escalation_chain_id = grafana_oncall_escalation_chain.default.id
42+
type = "notify_next_on_call_from_schedule"
43+
notify_on_call_from_schedule = grafana_oncall_schedule.example_schedule.id
44+
position = 1
45+
}

internal/resources/oncall/resource_escalation.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var escalationOptions = []string{
1818
"notify_persons",
1919
"notify_person_next_each_time",
2020
"notify_on_call_from_schedule",
21+
"notify_next_on_call_from_schedule",
2122
"trigger_webhook",
2223
"notify_user_group",
2324
"resolve",
@@ -66,7 +67,7 @@ func resourceEscalation() *common.Resource {
6667
"important": {
6768
Type: schema.TypeBool,
6869
Optional: true,
69-
Description: "Will activate \"important\" personal notification rules. Actual for steps: notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, notify_user_group and notify_team_members",
70+
Description: "Will activate \"important\" personal notification rules. Actual for steps: notify_persons, notify_person_next_each_time, notify_on_call_from_schedule, notify_next_on_call_from_schedule, notify_user_group and notify_team_members",
7071
},
7172
"duration": {
7273
Type: schema.TypeInt,
@@ -101,7 +102,7 @@ func resourceEscalation() *common.Resource {
101102
"num_alerts_in_window",
102103
"num_minutes_in_window",
103104
},
104-
Description: "ID of a Schedule for notify_on_call_from_schedule type step.",
105+
Description: "ID of a Schedule for notify_on_call_from_schedule or notify_next_on_call_from_schedule type step.",
105106
},
106107
"persons_to_notify": {
107108
Type: schema.TypeSet,
@@ -335,7 +336,7 @@ func resourceEscalationCreate(ctx context.Context, d *schema.ResourceData, clien
335336

336337
notifyOnCallFromScheduleData, notifyOnCallFromScheduleDataOk := d.GetOk("notify_on_call_from_schedule")
337338
if notifyOnCallFromScheduleDataOk {
338-
if typeData == "notify_on_call_from_schedule" {
339+
if typeData == "notify_on_call_from_schedule" || typeData == "notify_next_on_call_from_schedule" {
339340
createOptions.NotifyOnCallFromSchedule = notifyOnCallFromScheduleData.(string)
340341
} else {
341342
return diag.Errorf("notify_on_call_from_schedule can not be set with type: %s", typeData)
@@ -519,7 +520,7 @@ func resourceEscalationUpdate(ctx context.Context, d *schema.ResourceData, clien
519520

520521
notifyOnCallFromScheduleData, notifyOnCallFromScheduleDataOk := d.GetOk("notify_on_call_from_schedule")
521522
if notifyOnCallFromScheduleDataOk {
522-
if typeData == "notify_on_call_from_schedule" {
523+
if typeData == "notify_on_call_from_schedule" || typeData == "notify_next_on_call_from_schedule" {
523524
updateOptions.NotifyOnCallFromSchedule = notifyOnCallFromScheduleData.(string)
524525
}
525526
}

internal/resources/oncall/resource_escalation_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func TestAccOnCallEscalation_basic(t *testing.T) {
5050
resource.TestCheckResourceAttr("grafana_oncall_escalation.test-acc-escalation-policy-num-alerts", "position", "4"),
5151
resource.TestCheckResourceAttr("grafana_oncall_escalation.test-acc-escalation-policy-num-alerts", "num_alerts_in_window", "3"),
5252
resource.TestCheckResourceAttr("grafana_oncall_escalation.test-acc-escalation-policy-num-alerts", "num_minutes_in_window", "5"),
53+
54+
testAccCheckOnCallEscalationResourceExists("grafana_oncall_escalation.test-acc-escalation-policy-notify-next"),
55+
resource.TestCheckResourceAttr("grafana_oncall_escalation.test-acc-escalation-policy-notify-next", "type", "notify_next_on_call_from_schedule"),
56+
resource.TestCheckResourceAttr("grafana_oncall_escalation.test-acc-escalation-policy-notify-next", "position", "5"),
57+
resource.TestCheckResourceAttrSet("grafana_oncall_escalation.test-acc-escalation-policy-notify-next", "notify_on_call_from_schedule"),
5358
),
5459
},
5560
{
@@ -72,6 +77,11 @@ func TestAccOnCallEscalation_basic(t *testing.T) {
7277
ResourceName: "grafana_oncall_escalation.test-acc-escalation-policy-num-alerts",
7378
ImportStateVerify: true,
7479
},
80+
{
81+
ImportState: true,
82+
ResourceName: "grafana_oncall_escalation.test-acc-escalation-policy-notify-next",
83+
ImportStateVerify: true,
84+
},
7585
},
7686
})
7787
}
@@ -145,7 +155,20 @@ resource "grafana_oncall_escalation" "test-acc-escalation-policy-num-alerts" {
145155
num_minutes_in_window = 5
146156
position = 4
147157
}
148-
`, riName, riName, riName, reType, reDuration)
158+
159+
resource "grafana_oncall_schedule" "test-acc-schedule" {
160+
name = "acc-test-schedule-%s"
161+
type = "calendar"
162+
time_zone = "America/New_York"
163+
}
164+
165+
resource "grafana_oncall_escalation" "test-acc-escalation-policy-notify-next" {
166+
escalation_chain_id = grafana_oncall_escalation_chain.test-acc-escalation-chain.id
167+
type = "notify_next_on_call_from_schedule"
168+
notify_on_call_from_schedule = grafana_oncall_schedule.test-acc-schedule.id
169+
position = 5
170+
}
171+
`, riName, riName, riName, reType, reDuration, riName)
149172
}
150173

151174
func TestAccOnCallEscalation_notifyIfNumAlertsInWindow_wrongType(t *testing.T) {

pkg/generate/postprocessing/replace_references.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var knownReferences = []string{
103103
"grafana_notification_policy.mute_timings=grafana_mute_timing.name",
104104
"grafana_notification_policy.org_id=grafana_organization.id",
105105
"grafana_oncall_escalation.escalation_chain_id=grafana_oncall_escalation_chain.id",
106+
"grafana_oncall_escalation.notify_on_call_from_schedule=grafana_oncall_schedule.id",
106107
"grafana_oncall_integration.escalation_chain_id=grafana_oncall_escalation_chain.id",
107108
"grafana_oncall_route.escalation_chain_id=grafana_oncall_escalation_chain.id",
108109
"grafana_oncall_route.integration_id=grafana_oncall_integration.id",

0 commit comments

Comments
 (0)