diff --git a/docs/resources/oncall_on_call_shift.md b/docs/resources/oncall_on_call_shift.md index 19fbde26d..b502aaffd 100644 --- a/docs/resources/oncall_on_call_shift.md +++ b/docs/resources/oncall_on_call_shift.md @@ -110,6 +110,7 @@ output "emea_weekday__rolling_users" { - `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. +- `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") - `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, SU diff --git a/go.mod b/go.mod index 13de52a57..87533a792 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/fatih/color v1.17.0 github.com/go-openapi/runtime v0.28.0 github.com/go-openapi/strfmt v0.23.0 - github.com/grafana/amixr-api-go-client v0.0.13 // main branch + github.com/grafana/amixr-api-go-client v0.0.15 // main branch github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3 github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3 github.com/grafana/machine-learning-go-client v0.8.1 diff --git a/go.sum b/go.sum index 2d1e745ea..e1ec0c912 100644 --- a/go.sum +++ b/go.sum @@ -134,8 +134,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1 github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/grafana/amixr-api-go-client v0.0.13 h1:MwZ2DHnFOWY9EX7sMCd1GYvQSX6ZeEOiiONkomHQUNA= -github.com/grafana/amixr-api-go-client v0.0.13/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE= +github.com/grafana/amixr-api-go-client v0.0.15 h1:kq2C8QIsTm1lA7i8S5UA1PjeUJkSIRpNVXQXFLlxRAE= +github.com/grafana/amixr-api-go-client v0.0.15/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE= github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3 h1:CVLTffnWgBGvVaXfUUcSgFrZbiMzvj0/Hpi909zdeG0= github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3/go.mod h1:u9d0BESoKlztYm93CpoRleQjMbYBcZ+JOLHHP2nN6Wg= github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3 h1:W35ScJIkeyLuDlOo3F+u1JSRRvmoIYYf/ghA/17Y18Q= diff --git a/internal/resources/oncall/resource_shift.go b/internal/resources/oncall/resource_shift.go index c8862d0ce..0fa8d46b0 100644 --- a/internal/resources/oncall/resource_shift.go +++ b/internal/resources/oncall/resource_shift.go @@ -105,6 +105,12 @@ func resourceOnCallShift() *common.Resource { "interval", }, }, + "until": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + 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\")", + }, "users": { Type: schema.TypeSet, Elem: &schema.Schema{ @@ -307,6 +313,16 @@ func resourceOnCallShiftCreate(ctx context.Context, d *schema.ResourceData, clie } } + untilData, untilOk := d.GetOk("until") + if untilOk { + if typeData == singleEvent { + return diag.Errorf("`until` can not be set with type: %s", typeData) + } else { + u := untilData.(string) + createOptions.Until = &u + } + } + timeZoneData, timeZoneOk := d.GetOk("time_zone") if timeZoneOk { tz := timeZoneData.(string) @@ -418,6 +434,16 @@ func resourceOnCallShiftUpdate(ctx context.Context, d *schema.ResourceData, clie } } + untilData, untilOk := d.GetOk("until") + if untilOk { + if typeData == singleEvent { + return diag.Errorf("`until` can not be set with type: %s", typeData) + } else { + u := untilData.(string) + updateOptions.Until = &u + } + } + timeZoneData, timeZoneOk := d.GetOk("time_zone") if timeZoneOk { tz := timeZoneData.(string) @@ -471,6 +497,7 @@ func resourceOnCallShiftRead(ctx context.Context, d *schema.ResourceData, client d.Set("type", onCallShift.Type) d.Set("level", onCallShift.Level) d.Set("start", onCallShift.Start) + d.Set("until", onCallShift.Until) d.Set("duration", onCallShift.Duration) d.Set("frequency", onCallShift.Frequency) d.Set("week_start", onCallShift.WeekStart) diff --git a/internal/resources/oncall/resource_shift_test.go b/internal/resources/oncall/resource_shift_test.go index e92cd9b10..0b43c650f 100644 --- a/internal/resources/oncall/resource_shift_test.go +++ b/internal/resources/oncall/resource_shift_test.go @@ -38,6 +38,7 @@ func TestAccOnCallOnCallShift_basic(t *testing.T) { resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.#", "2"), resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.0", "FR"), resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "by_day.1", "MO"), + resource.TestCheckNoResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "until"), ), }, { @@ -65,6 +66,13 @@ func TestAccOnCallOnCallShift_basic(t *testing.T) { resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "name", shiftName), ), }, + { + Config: testAccOnCallOnCallShiftConfigUntil(scheduleName, shiftName), + Check: resource.ComposeTestCheckFunc( + testAccCheckOnCallOnCallShiftResourceExists("grafana_oncall_on_call_shift.test-acc-on_call_shift"), + resource.TestCheckResourceAttr("grafana_oncall_on_call_shift.test-acc-on_call_shift", "until", "2020-10-04T16:00:00"), + ), + }, }, }) } @@ -188,6 +196,29 @@ resource "grafana_oncall_on_call_shift" "test-acc-on_call_shift" { `, scheduleName, shiftName) } +func testAccOnCallOnCallShiftConfigUntil(scheduleName, shiftName string) string { + return fmt.Sprintf(` +resource "grafana_oncall_schedule" "test-acc-schedule" { + type = "calendar" + name = "%s" + time_zone = "UTC" +} + +resource "grafana_oncall_on_call_shift" "test-acc-on_call_shift" { + name = "%s" + type = "recurrent_event" + start = "2020-09-04T16:00:00" + until = "2020-10-04T16:00:00" + duration = 3600 + level = 1 + frequency = "weekly" + week_start = "SU" + interval = 2 + by_day = ["MO", "FR"] +} +`, scheduleName, shiftName) +} + func testAccCheckOnCallOnCallShiftResourceExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name]