Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add until parameter to grafana_oncall_on_call_shift resource #1830

Merged
merged 9 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/oncall_on_call_shift.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
27 changes: 27 additions & 0 deletions internal/resources/oncall/resource_shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions internal/resources/oncall/resource_shift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"),
),
},
},
})
}
Expand Down Expand Up @@ -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]
Expand Down
Loading