Skip to content

Commit 16230c5

Browse files
authored
oncall: Allow oncall schedules of type web (#2230)
* allow oncall schedules of type web * ignore schedule shifts and timezone unless type is calendar * move schedule type check to func to satify linter
1 parent 6644b8e commit 16230c5

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

docs/resources/oncall_schedule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resource "grafana_oncall_schedule" "example_schedule" {
6565
### Required
6666

6767
- `name` (String) The schedule's name.
68-
- `type` (String) The schedule's type. Valid values are `ical`, `calendar`.
68+
- `type` (String) The schedule's type. Valid values are `ical`, `calendar`, `web`.
6969

7070
### Optional
7171

internal/resources/oncall/resource_schedule.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
var scheduleTypeOptions = []string{
1717
"ical",
1818
"calendar",
19+
"web",
1920
}
2021

2122
func resourceSchedule() *common.Resource {
@@ -162,7 +163,7 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, client
162163

163164
shiftsData, shiftsOk := d.GetOk("shifts")
164165
if shiftsOk {
165-
if typeData == "calendar" {
166+
if isScheduleTypeCalendar(typeData) {
166167
shiftsDataSlice := common.SetToStringSlice(shiftsData.(*schema.Set))
167168
createOptions.Shifts = &shiftsDataSlice
168169
} else {
@@ -172,7 +173,7 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, client
172173

173174
timeZoneData, timeZoneOk := d.GetOk("time_zone")
174175
if timeZoneOk {
175-
if typeData == "calendar" {
176+
if isScheduleTypeCalendar(typeData) {
176177
createOptions.TimeZone = timeZoneData.(string)
177178
} else {
178179
return diag.Errorf("time_zone can not be set with type: %s", typeData)
@@ -225,7 +226,7 @@ func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, client
225226

226227
timeZoneData, timeZoneOk := d.GetOk("time_zone")
227228
if timeZoneOk {
228-
if typeData == "calendar" {
229+
if isScheduleTypeCalendar(typeData) {
229230
updateOptions.TimeZone = timeZoneData.(string)
230231
} else {
231232
return diag.Errorf("time_zone can not be set with type: %s", typeData)
@@ -234,7 +235,7 @@ func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, client
234235

235236
shiftsData, shiftsOk := d.GetOk("shifts")
236237
if shiftsOk {
237-
if typeData == "calendar" {
238+
if isScheduleTypeCalendar(typeData) {
238239
shiftsDataSlice := common.SetToStringSlice(shiftsData.(*schema.Set))
239240
updateOptions.Shifts = &shiftsDataSlice
240241
} else {
@@ -268,9 +269,12 @@ func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, client *o
268269
d.Set("ical_url_primary", schedule.ICalUrlPrimary)
269270
d.Set("ical_url_overrides", schedule.ICalUrlOverrides)
270271
d.Set("enable_web_overrides", schedule.EnableWebOverrides)
271-
d.Set("time_zone", schedule.TimeZone)
272272
d.Set("slack", flattenScheduleSlack(schedule.Slack))
273-
d.Set("shifts", schedule.Shifts)
273+
274+
if isScheduleTypeCalendar(schedule.Type) {
275+
d.Set("time_zone", schedule.TimeZone)
276+
d.Set("shifts", schedule.Shifts)
277+
}
274278

275279
return nil
276280
}
@@ -317,3 +321,7 @@ func expandScheduleSlack(in []interface{}) *onCallAPI.SlackSchedule {
317321

318322
return &slackSchedule
319323
}
324+
325+
func isScheduleTypeCalendar(t string) bool {
326+
return t == "calendar"
327+
}

internal/resources/oncall/resource_schedule_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func TestAccOnCallSchedule_basic(t *testing.T) {
5252
resource.TestCheckResourceAttr("grafana_oncall_schedule.test-acc-schedule", "enable_web_overrides", "false"),
5353
),
5454
},
55+
{
56+
Config: testAccOnCallWebScheduleConfig(scheduleName),
57+
Check: resource.ComposeTestCheckFunc(
58+
testAccCheckOnCallScheduleResourceExists("grafana_oncall_schedule.test-acc-schedule"),
59+
resource.TestCheckResourceAttr("grafana_oncall_schedule.test-acc-schedule", "type", "web"),
60+
),
61+
},
5562
{
5663
ImportState: true,
5764
ResourceName: "grafana_oncall_schedule.test-acc-schedule",
@@ -85,6 +92,15 @@ resource "grafana_oncall_schedule" "test-acc-schedule" {
8592
`, scheduleName)
8693
}
8794

95+
func testAccOnCallWebScheduleConfig(scheduleName string) string {
96+
return fmt.Sprintf(`
97+
resource "grafana_oncall_schedule" "test-acc-schedule" {
98+
name = "%s"
99+
type = "web"
100+
}
101+
`, scheduleName)
102+
}
103+
88104
func testAccOnCallScheduleConfigOverrides(scheduleName string, enableWebOverrides bool) string {
89105
return fmt.Sprintf(`
90106
resource "grafana_oncall_schedule" "test-acc-schedule" {

0 commit comments

Comments
 (0)