Skip to content
Open
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
16 changes: 16 additions & 0 deletions examples/resources/grafana_oncall_schedule/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ resource "grafana_oncall_schedule" "example_schedule" {
]
ical_url_overrides = "https://example.com/example_overrides_ical.ics"
}

// Web based schedule
resource "grafana_oncall_schedule" "example_schedule" {
name = "Example Calendar Schadule"
type = "web"
time_zone = "America/New_York"

// Optional: specify the team to which the schedule belongs
team_id = data.grafana_oncall_team.my_team.id

// Is highly recommended to set ignore changes on all properties to avoid
// recreating the schedule all the time due to changes on the Web UI.
lifecycle {
ignore_changes = all
}
}
42 changes: 36 additions & 6 deletions internal/resources/oncall/resource_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func resourceSchedule() *common.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

CustomizeDiff: resourceScheduleCustomizeDiff,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -173,10 +175,10 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, client

timeZoneData, timeZoneOk := d.GetOk("time_zone")
if timeZoneOk {
if isScheduleTypeCalendar(typeData) {
createOptions.TimeZone = timeZoneData.(string)
} else {
if isScheduleTypeiCal(typeData) {
return diag.Errorf("time_zone can not be set with type: %s", typeData)
} else {
createOptions.TimeZone = timeZoneData.(string)
}
}

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

timeZoneData, timeZoneOk := d.GetOk("time_zone")
if timeZoneOk {
if isScheduleTypeCalendar(typeData) {
updateOptions.TimeZone = timeZoneData.(string)
} else {
if isScheduleTypeiCal(typeData) {
return diag.Errorf("time_zone can not be set with type: %s", typeData)
} else {
updateOptions.TimeZone = timeZoneData.(string)
}
}

Expand Down Expand Up @@ -325,3 +327,31 @@ func expandScheduleSlack(in []any) *onCallAPI.SlackSchedule {
func isScheduleTypeCalendar(t string) bool {
return t == "calendar"
}

func isScheduleTypeiCal(t string) bool {
return t == "ical"
}

func resourceScheduleCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
oldType, _ := d.GetChange("type")

if oldType == nil {
return nil
}

if oldType.(string) == "web" {
for _, key := range d.GetChangedKeysPrefix("") {
if key == "id" {
continue
}

if err := d.ForceNew(key); err != nil {
return err
}

return nil
}
}

return nil
}