Skip to content

[ResponseOps] Maintenance Window Resource #1037

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Remove occurrences from maintenance window resource.
  • Loading branch information
adcoelho committed May 20, 2025
commit bf84803175e85d5beddd02cf6d484c1024e0dbb3
33 changes: 15 additions & 18 deletions internal/clients/kibana/maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ func maintenanceWindowResponseToModel(spaceId string, res *alerting.MaintenanceW
unwrappedRecurring := unwrapOptionalField(res.Schedule.Custom.Recurring)

recurring = &models.MaintenanceWindowScheduleRecurring{
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
Occurrences: unwrappedRecurring.Occurrences,
OnWeekDay: &unwrappedRecurring.OnWeekDay,
OnMonthDay: &unwrappedRecurring.OnMonthDay,
OnMonth: &unwrappedRecurring.OnMonth,
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
OnWeekDay: &unwrappedRecurring.OnWeekDay,
OnMonthDay: &unwrappedRecurring.OnMonthDay,
OnMonth: &unwrappedRecurring.OnMonth,
}
}

Expand Down Expand Up @@ -91,12 +90,11 @@ func CreateMaintenanceWindow(ctx context.Context, apiClient ApiClient, maintenan
unwrappedOnMonth := unwrapOptionalField(unwrappedRecurring.OnMonth)

recurring = &alerting.CreateMaintenanceWindowRequestScheduleCustomRecurring{
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
Occurrences: unwrappedRecurring.Occurrences,
OnWeekDay: unwrappedOnWeekDay,
OnMonthDay: unwrappedOnMonthDay,
OnMonth: unwrappedOnMonth,
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
OnWeekDay: unwrappedOnWeekDay,
OnMonthDay: unwrappedOnMonthDay,
OnMonth: unwrappedOnMonth,
}
}

Expand Down Expand Up @@ -215,12 +213,11 @@ func UpdateMaintenanceWindow(ctx context.Context, apiClient ApiClient, maintenan
unwrappedOnMonth := unwrapOptionalField(unwrappedRecurring.OnMonth)

recurring = &alerting.CreateMaintenanceWindowRequestScheduleCustomRecurring{
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
Occurrences: unwrappedRecurring.Occurrences,
OnWeekDay: unwrappedOnWeekDay,
OnMonthDay: unwrappedOnMonthDay,
OnMonth: unwrappedOnMonth,
End: unwrappedRecurring.End,
Every: unwrappedRecurring.Every,
OnWeekDay: unwrappedOnWeekDay,
OnMonthDay: unwrappedOnMonthDay,
OnMonth: unwrappedOnMonth,
}
}

Expand Down
22 changes: 10 additions & 12 deletions internal/clients/kibana/maintenance_window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ func Test_maintenanceWindowResponseToModel(t *testing.T) {
Start: "1999-02-02T05:00:00.200Z",
Timezone: utils.Pointer("Asia/Taipei"),
Recurring: &alerting.MaintenanceWindowResponsePropertiesScheduleCustomRecurring{
End: utils.Pointer("2029-05-17T05:05:00.000Z"),
Every: utils.Pointer("20d"),
Occurrences: utils.Pointer(float32(30)),
OnMonth: []float32{2},
OnMonthDay: []float32{1},
OnWeekDay: []string{"WE", "TU"},
End: utils.Pointer("2029-05-17T05:05:00.000Z"),
Every: utils.Pointer("20d"),
OnMonth: []float32{2},
OnMonthDay: []float32{1},
OnWeekDay: []string{"WE", "TU"},
},
},
},
Expand All @@ -107,12 +106,11 @@ func Test_maintenanceWindowResponseToModel(t *testing.T) {
Start: "1999-02-02T05:00:00.200Z",
Timezone: utils.Pointer("Asia/Taipei"),
Recurring: &models.MaintenanceWindowScheduleRecurring{
End: utils.Pointer("2029-05-17T05:05:00.000Z"),
Every: utils.Pointer("20d"),
Occurrences: utils.Pointer(float32(30)),
OnMonth: &[]float32{2},
OnMonthDay: &[]float32{1},
OnWeekDay: &[]string{"WE", "TU"},
End: utils.Pointer("2029-05-17T05:05:00.000Z"),
Every: utils.Pointer("20d"),
OnMonth: &[]float32{2},
OnMonthDay: &[]float32{1},
OnWeekDay: &[]string{"WE", "TU"},
},
},
Scope: &models.MaintenanceWindowScope{
Expand Down
12 changes: 0 additions & 12 deletions internal/kibana/maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ func ResourceMaintenanceWindow() *schema.Resource {
ValidateFunc: validation.IntBetween(1, 12),
},
},
"occurrences": {
Description: "The total number of recurrences of the schedule.",
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(0),
},
},
},
},
Expand Down Expand Up @@ -250,11 +244,6 @@ func getScheduleFromResourceData(d *schema.ResourceData) (models.MaintenanceWind

}

if v, ok := d.GetOk("custom_schedule.0.recurring.0.occurrences"); ok {
occurrences := v.(int)
recurring.Occurrences = utils.Pointer(float32(occurrences))
}

schedule.Recurring = &recurring
}

Expand Down Expand Up @@ -402,7 +391,6 @@ func resourceMaintenanceWindowRead(ctx context.Context, d *schema.ResourceData,
"on_week_day": maintenanceWindow.CustomSchedule.Recurring.OnWeekDay,
"on_month_day": maintenanceWindow.CustomSchedule.Recurring.OnMonthDay,
"on_month": maintenanceWindow.CustomSchedule.Recurring.OnMonth,
"occurrences": maintenanceWindow.CustomSchedule.Recurring.Occurrences,
})
} else {
recurring = nil
Expand Down
4 changes: 0 additions & 4 deletions internal/kibana/maintenance_window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestAccResourceMaintenanceWindow(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.end", "2029-05-17T05:05:00.000Z"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.on_week_day.0", "MO"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.on_week_day.1", "TU"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.occurrences", "0"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "scope.0.alerting.0.kql", "_id: '1234'"),
),
},
Expand All @@ -57,7 +56,6 @@ func TestAccResourceMaintenanceWindow(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.on_month_day.2", "3"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.on_month.0", "4"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.on_month.1", "5"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "custom_schedule.0.recurring.0.occurrences", "10"),
resource.TestCheckResourceAttr("elasticstack_kibana_maintenance_window.test_maintenance_window", "scope.0.alerting.0.kql", "_id: 'foobar'"),
),
},
Expand All @@ -82,7 +80,6 @@ resource "elasticstack_kibana_maintenance_window" "test_maintenance_window" {
every = "20d"
end = "2029-05-17T05:05:00.000Z"
on_week_day = ["MO", "TU"]
occurrences = 0
}
}

Expand Down Expand Up @@ -111,7 +108,6 @@ resource "elasticstack_kibana_maintenance_window" "test_maintenance_window" {
every = "21d"
on_month_day = [1, 2, 3]
on_month = [4, 5]
occurrences = 10
}
}

Expand Down
11 changes: 5 additions & 6 deletions internal/models/maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ type MaintenanceWindowSchedule struct {
}

type MaintenanceWindowScheduleRecurring struct {
End *string
Every *string
OnWeekDay *[]string
OnMonthDay *[]float32
OnMonth *[]float32
Occurrences *float32
End *string
Every *string
OnWeekDay *[]string
OnMonthDay *[]float32
OnMonth *[]float32
}