Skip to content

Commit c20d360

Browse files
authored
feat: add until parameter to grafana_oncall_on_call_shift resource (#1830)
1 parent a4a2b46 commit c20d360

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

docs/resources/oncall_on_call_shift.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ output "emea_weekday__rolling_users" {
110110
- `start_rotation_from_user_index` (Number) The index of the list of users in rolling_users, from which on-call rotation starts.
111111
- `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.
112112
- `time_zone` (String) The shift's timezone. Overrides schedule's timezone.
113+
- `until` (String) The end time of recurrent on-call shifts (endless if null). This parameter takes a date format as yyyy-MM-dd'T'HH:mm:ss (for example "2020-09-05T08:00:00")
113114
- `users` (Set of String) The list of on-call users (for single_event and recurrent_event event type).
114115
- `week_start` (String) Start day of the week in iCal format. Can be MO, TU, WE, TH, FR, SA, SU
115116

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/fatih/color v1.17.0
1010
github.com/go-openapi/runtime v0.28.0
1111
github.com/go-openapi/strfmt v0.23.0
12-
github.com/grafana/amixr-api-go-client v0.0.13 // main branch
12+
github.com/grafana/amixr-api-go-client v0.0.15 // main branch
1313
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3
1414
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3
1515
github.com/grafana/machine-learning-go-client v0.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1
134134
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
135135
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
136136
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
137-
github.com/grafana/amixr-api-go-client v0.0.13 h1:MwZ2DHnFOWY9EX7sMCd1GYvQSX6ZeEOiiONkomHQUNA=
138-
github.com/grafana/amixr-api-go-client v0.0.13/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
137+
github.com/grafana/amixr-api-go-client v0.0.15 h1:kq2C8QIsTm1lA7i8S5UA1PjeUJkSIRpNVXQXFLlxRAE=
138+
github.com/grafana/amixr-api-go-client v0.0.15/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
139139
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3 h1:CVLTffnWgBGvVaXfUUcSgFrZbiMzvj0/Hpi909zdeG0=
140140
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3/go.mod h1:u9d0BESoKlztYm93CpoRleQjMbYBcZ+JOLHHP2nN6Wg=
141141
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3 h1:W35ScJIkeyLuDlOo3F+u1JSRRvmoIYYf/ghA/17Y18Q=

internal/resources/oncall/resource_shift.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ func resourceOnCallShift() *common.Resource {
105105
"interval",
106106
},
107107
},
108+
"until": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
ValidateFunc: validation.StringIsNotEmpty,
112+
Description: "The end time of recurrent on-call shifts (endless if null). This parameter takes a date format as yyyy-MM-dd'T'HH:mm:ss (for example \"2020-09-05T08:00:00\")",
113+
},
108114
"users": {
109115
Type: schema.TypeSet,
110116
Elem: &schema.Schema{
@@ -307,6 +313,16 @@ func resourceOnCallShiftCreate(ctx context.Context, d *schema.ResourceData, clie
307313
}
308314
}
309315

316+
untilData, untilOk := d.GetOk("until")
317+
if untilOk {
318+
if typeData == singleEvent {
319+
return diag.Errorf("`until` can not be set with type: %s", typeData)
320+
} else {
321+
u := untilData.(string)
322+
createOptions.Until = &u
323+
}
324+
}
325+
310326
timeZoneData, timeZoneOk := d.GetOk("time_zone")
311327
if timeZoneOk {
312328
tz := timeZoneData.(string)
@@ -418,6 +434,16 @@ func resourceOnCallShiftUpdate(ctx context.Context, d *schema.ResourceData, clie
418434
}
419435
}
420436

437+
untilData, untilOk := d.GetOk("until")
438+
if untilOk {
439+
if typeData == singleEvent {
440+
return diag.Errorf("`until` can not be set with type: %s", typeData)
441+
} else {
442+
u := untilData.(string)
443+
updateOptions.Until = &u
444+
}
445+
}
446+
421447
timeZoneData, timeZoneOk := d.GetOk("time_zone")
422448
if timeZoneOk {
423449
tz := timeZoneData.(string)
@@ -471,6 +497,7 @@ func resourceOnCallShiftRead(ctx context.Context, d *schema.ResourceData, client
471497
d.Set("type", onCallShift.Type)
472498
d.Set("level", onCallShift.Level)
473499
d.Set("start", onCallShift.Start)
500+
d.Set("until", onCallShift.Until)
474501
d.Set("duration", onCallShift.Duration)
475502
d.Set("frequency", onCallShift.Frequency)
476503
d.Set("week_start", onCallShift.WeekStart)

internal/resources/oncall/resource_shift_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestAccOnCallOnCallShift_basic(t *testing.T) {
3838
resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.#", "2"),
3939
resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.0", "FR"),
4040
resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.1", "MO"),
41+
resource.TestCheckNoResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "until"),
4142
),
4243
},
4344
{
@@ -65,6 +66,13 @@ func TestAccOnCallOnCallShift_basic(t *testing.T) {
6566
resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "name", shiftName),
6667
),
6768
},
69+
{
70+
Config: testAccOnCallOnCallShiftConfigUntil(scheduleName, shiftName),
71+
Check: resource.ComposeTestCheckFunc(
72+
testAccCheckOnCallOnCallShiftResourceExists("grafana_oncall_on_call_shift.test-acc-on_call_shift"),
73+
resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "until", "2020-10-04T16:00:00"),
74+
),
75+
},
6876
},
6977
})
7078
}
@@ -188,6 +196,29 @@ resource "grafana_oncall_on_call_shift" "test-acc-on_call_shift" {
188196
`, scheduleName, shiftName)
189197
}
190198

199+
func testAccOnCallOnCallShiftConfigUntil(scheduleName, shiftName string) string {
200+
return fmt.Sprintf(`
201+
resource "grafana_oncall_schedule" "test-acc-schedule" {
202+
type = "calendar"
203+
name = "%s"
204+
time_zone = "UTC"
205+
}
206+
207+
resource "grafana_oncall_on_call_shift" "test-acc-on_call_shift" {
208+
name = "%s"
209+
type = "recurrent_event"
210+
start = "2020-09-04T16:00:00"
211+
until = "2020-10-04T16:00:00"
212+
duration = 3600
213+
level = 1
214+
frequency = "weekly"
215+
week_start = "SU"
216+
interval = 2
217+
by_day = ["MO", "FR"]
218+
}
219+
`, scheduleName, shiftName)
220+
}
221+
191222
func testAccCheckOnCallOnCallShiftResourceExists(name string) resource.TestCheckFunc {
192223
return func(s *terraform.State) error {
193224
rs, ok := s.RootModule().Resources[name]

0 commit comments

Comments
 (0)