data "grafana_oncall_user" "alex" {
username = "alex"
}
resource "grafana_oncall_on_call_shift" "example_shift" {
name = "Example Shift"
type = "recurrent_event"
start = "2020-09-07T14:00:00"
duration = 60 * 30
frequency = "weekly"
interval = 2
by_day = ["MO", "FR"]
week_start = "MO"
users = [
data.grafana_oncall_user.alex.id
]
time_zone = "UTC"
}
////////
// Advanced example
////////
// Importing users
data "grafana_oncall_user" "all_users" {
// Extract flat set of all users from the all teams
for_each = toset(flatten([
for team_name, username_list in local.teams : [
username_list
]
]))
username = each.key
}
// ON-CALL GROUPS / TEAMS
locals {
teams = {
emea = [
"alfa@grafana.com",
"bravo@grafana.com",
"charlie@grafana.com",
"echo@grafana.com",
"delta@grafana.com",
"foxtrot@grafana.com",
"golf@grafana.com",
]
}
// oncall API operates with resources ID's, so we convert emails into ID's
teams_map_of_user_id = { for team_name, username_list in local.teams : team_name => [
for username in username_list : lookup(data.grafana_oncall_user.all_users, username).id] }
users_map_by_id = { for username, oncall_user in data.grafana_oncall_user.all_users : oncall_user.id => oncall_user }
}
// A 12 hour shift on week days with the on-call person rotating weekly.
resource "grafana_oncall_on_call_shift" "emea_weekday_shift" {
name = "EMEA Weekday Shift"
type = "rolling_users"
start = "2022-02-28T03:00:00"
duration = 60 * 60 * 12 // 12 hours
frequency = "weekly"
interval = 1
by_day = ["MO", "TU", "WE", "TH", "FR"]
week_start = "MO"
// Run `terraform refresh` and `terraform output` to see the flattened list of users in the rotation
rolling_users = [for k in flatten([
local.teams_map_of_user_id.emea,
]) : [k]]
start_rotation_from_user_index = 0
}
output "emea_weekday__rolling_users" {
value = [for k in flatten(grafana_oncall_on_call_shift.emea_weekday_shift.rolling_users) : lookup(local.users_map_by_id, k).username]
}
duration
(Number) The duration of the event.name
(String) The shift's name.start
(String) The start time of the on-call shift. This parameter takes a date format as yyyy-MM-dd'T'HH:mm:ss (for example "2020-09-05T08:00:00")type
(String) The shift's type. Can be rolling_users, recurrent_event, single_eventby_day
(Set of String) This parameter takes a list of days in iCal format. Can be MO, TU, WE, TH, FR, SA, SUby_month
(Set of Number) This parameter takes a list of months. Valid values are 1 to 12by_monthday
(Set of Number) This parameter takes a list of days of the month. Valid values are 1 to 31 or -31 to -1frequency
(String) The frequency of the event. Can be hourly, daily, weekly, monthlyinterval
(Number) The positive integer representing at which intervals the recurrence rule repeats.level
(Number) The priority level. The higher the value, the higher the priority.rolling_users
(List of Set of String) The list of lists with on-call users (for rolling_users event type)start_rotation_from_user_index
(Number) The index of the list of users in rolling_users, from which on-call rotation starts.team_id
(String) The ID of the OnCall team. To get one, create a team in Grafana, and navigate to the OnCall plugin (to sync the team with OnCall). You can then get the ID using the grafana_oncall_team
datasource.time_zone
(String) The shift's timezone. Overrides schedule's timezone.users
(Set of String) The list of on-call users (for single_event and recurrent_event event type).week_start
(String) Start day of the week in iCal format. Can be MO, TU, WE, TH, FR, SA, SUid
(String) The ID of this resource.Import is supported using the following syntax:
terraform import grafana_oncall_on_call_shift.name "{{ id }}"