Skip to content

Commit 29af19f

Browse files
fix(oncall): enable creation of web based schedules through tf
1 parent d08d87c commit 29af19f

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

examples/resources/grafana_oncall_schedule/resource.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,19 @@ resource "grafana_oncall_schedule" "example_schedule" {
4242
]
4343
ical_url_overrides = "https://example.com/example_overrides_ical.ics"
4444
}
45+
46+
// Web based schedule
47+
resource "grafana_oncall_schedule" "example_schedule" {
48+
name = "Example Calendar Schadule"
49+
type = "web"
50+
time_zone = "America/New_York"
51+
52+
// Optional: specify the team to which the schedule belongs
53+
team_id = data.grafana_oncall_team.my_team.id
54+
55+
// Is highly recommended to set ignore changes on all properties to avoid
56+
// recreating the schedule all the time due to changes on the Web UI.
57+
lifecycle {
58+
ignore_changes = all
59+
}
60+
}

internal/resources/oncall/resource_schedule.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func resourceSchedule() *common.Resource {
3232
StateContext: schema.ImportStatePassthroughContext,
3333
},
3434

35+
CustomizeDiff: resourceScheduleCustomizeDiff,
36+
3537
Schema: map[string]*schema.Schema{
3638
"name": {
3739
Type: schema.TypeString,
@@ -173,10 +175,10 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, client
173175

174176
timeZoneData, timeZoneOk := d.GetOk("time_zone")
175177
if timeZoneOk {
176-
if isScheduleTypeCalendar(typeData) {
177-
createOptions.TimeZone = timeZoneData.(string)
178-
} else {
178+
if isScheduleTypeiCal(typeData) {
179179
return diag.Errorf("time_zone can not be set with type: %s", typeData)
180+
} else {
181+
createOptions.TimeZone = timeZoneData.(string)
180182
}
181183
}
182184

@@ -226,10 +228,10 @@ func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, client
226228

227229
timeZoneData, timeZoneOk := d.GetOk("time_zone")
228230
if timeZoneOk {
229-
if isScheduleTypeCalendar(typeData) {
230-
updateOptions.TimeZone = timeZoneData.(string)
231-
} else {
231+
if isScheduleTypeiCal(typeData) {
232232
return diag.Errorf("time_zone can not be set with type: %s", typeData)
233+
} else {
234+
updateOptions.TimeZone = timeZoneData.(string)
233235
}
234236
}
235237

@@ -325,3 +327,31 @@ func expandScheduleSlack(in []any) *onCallAPI.SlackSchedule {
325327
func isScheduleTypeCalendar(t string) bool {
326328
return t == "calendar"
327329
}
330+
331+
func isScheduleTypeiCal(t string) bool {
332+
return t == "ical"
333+
}
334+
335+
func resourceScheduleCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
336+
oldType, _ := d.GetChange("type")
337+
338+
if oldType == nil {
339+
return nil
340+
}
341+
342+
if oldType.(string) == "web" {
343+
for _, key := range d.GetChangedKeysPrefix("") {
344+
if key == "id" {
345+
continue
346+
}
347+
348+
if err := d.ForceNew(key); err != nil {
349+
return err
350+
}
351+
352+
return nil
353+
}
354+
}
355+
356+
return nil
357+
}

0 commit comments

Comments
 (0)