Skip to content

Commit 07068c7

Browse files
committed
Addressing PR comments 1
1 parent d731442 commit 07068c7

File tree

5 files changed

+16
-35
lines changed

5 files changed

+16
-35
lines changed

examples/resources/elasticstack_kibana_maintenance_window/resource.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ resource "elasticstack_kibana_maintenance_window" "my_maintenance_window" {
77
title = "UPDATE TEST"
88
enabled = true
99

10-
custom_schedule {
10+
custom_schedule = {
1111
start = "1993-01-01T05:00:00.200Z"
1212
duration = "12d"
1313

14-
recurring {
14+
recurring = {
1515
every = "21d"
1616
on_week_day = ["MO", "+3TU", "-2FR"]
1717
on_month_day = [1, 2, 4, 6, 7]
1818
on_month = [12]
1919
}
2020
}
2121

22-
scope {
23-
alerting {
22+
scope = {
23+
alerting = {
2424
kql = "_id: '1234'"
2525
}
2626
}

internal/kibana/maintenance_window/delete.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ func (r *MaintenanceWindowResource) Delete(ctx context.Context, req resource.Del
1616
return
1717
}
1818

19-
serverVersion, sdkDiags := r.client.ServerVersion(ctx)
20-
if sdkDiags.HasError() {
21-
return
22-
}
23-
24-
serverFlavor, sdkDiags := r.client.ServerFlavor(ctx)
25-
if sdkDiags.HasError() {
26-
return
27-
}
28-
29-
diags = validateMaintenanceWindowServer(serverVersion, serverFlavor)
30-
if diags.HasError() {
31-
return
32-
}
33-
3419
client, err := r.client.GetKibanaOapiClient()
3520
if err != nil {
3621
resp.Diagnostics.AddError(err.Error(), "")

internal/kibana/maintenance_window/models.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
88
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
9+
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
910
"github.com/hashicorp/terraform-plugin-framework/diag"
1011
"github.com/hashicorp/terraform-plugin-framework/types"
1112
)
@@ -79,19 +80,19 @@ func (model MaintenanceWindowModel) toAPICreateRequest(ctx context.Context) (kba
7980
body.Schedule.Custom.Recurring.Occurrences = &occurrences
8081
}
8182

82-
if !model.CustomSchedule.Recurring.OnWeekDay.IsNull() && !model.CustomSchedule.Recurring.OnWeekDay.IsUnknown() {
83+
if utils.IsKnown(model.CustomSchedule.Recurring.OnWeekDay) {
8384
var onWeekDay []string
8485
diags.Append(model.CustomSchedule.Recurring.OnWeekDay.ElementsAs(ctx, &onWeekDay, true)...)
8586
body.Schedule.Custom.Recurring.OnWeekDay = &onWeekDay
8687
}
8788

88-
if !model.CustomSchedule.Recurring.OnMonth.IsNull() && !model.CustomSchedule.Recurring.OnMonth.IsUnknown() {
89+
if utils.IsKnown(model.CustomSchedule.Recurring.OnMonth) {
8990
var onMonth []float32
9091
diags.Append(model.CustomSchedule.Recurring.OnMonth.ElementsAs(ctx, &onMonth, true)...)
9192
body.Schedule.Custom.Recurring.OnMonth = &onMonth
9293
}
9394

94-
if !model.CustomSchedule.Recurring.OnMonthDay.IsNull() && !model.CustomSchedule.Recurring.OnMonthDay.IsUnknown() {
95+
if utils.IsKnown(model.CustomSchedule.Recurring.OnMonthDay) {
9596
var onMonthDay []float32
9697
diags.Append(model.CustomSchedule.Recurring.OnMonthDay.ElementsAs(ctx, &onMonthDay, true)...)
9798
body.Schedule.Custom.Recurring.OnMonthDay = &onMonthDay
@@ -162,14 +163,9 @@ func (model *MaintenanceWindowModel) fromAPIReadResponse(ctx context.Context, da
162163
func (model MaintenanceWindowModel) toAPIUpdateRequest(ctx context.Context) (kbapi.PatchMaintenanceWindowIdJSONRequestBody, diag.Diagnostics) {
163164
var diags = diag.Diagnostics{}
164165

165-
body := kbapi.PatchMaintenanceWindowIdJSONRequestBody{}
166-
167-
if !model.Enabled.IsNull() {
168-
body.Enabled = model.Enabled.ValueBoolPointer()
169-
}
170-
171-
if !model.Title.IsNull() {
172-
body.Title = model.Title.ValueStringPointer()
166+
body := kbapi.PatchMaintenanceWindowIdJSONRequestBody{
167+
Enabled: model.Enabled.ValueBoolPointer(),
168+
Title: model.Title.ValueStringPointer(),
173169
}
174170

175171
schedule := struct {
@@ -207,7 +203,7 @@ func (model MaintenanceWindowModel) toAPIUpdateRequest(ctx context.Context) (kba
207203

208204
body.Schedule = &schedule
209205

210-
if !model.CustomSchedule.Timezone.IsNull() && !model.CustomSchedule.Timezone.IsUnknown() {
206+
if utils.IsKnown(model.CustomSchedule.Timezone) {
211207
body.Schedule.Custom.Timezone = model.CustomSchedule.Timezone.ValueStringPointer()
212208
}
213209

internal/kibana/maintenance_window/read.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ func (r *MaintenanceWindowResource) Read(ctx context.Context, req resource.ReadR
3838
}
3939

4040
viewID, spaceID := stateModel.getMaintenanceWindowIDAndSpaceID()
41-
dataView, diags := kibana_oapi.GetMaintenanceWindow(ctx, client, spaceID, viewID)
41+
maintenanceWindow, diags := kibana_oapi.GetMaintenanceWindow(ctx, client, spaceID, viewID)
4242
resp.Diagnostics.Append(diags...)
4343
if resp.Diagnostics.HasError() {
4444
return
4545
}
4646

47-
if dataView == nil {
47+
if maintenanceWindow == nil {
4848
resp.State.RemoveResource(ctx)
4949
return
5050
}
5151

52-
diags = stateModel.fromAPIReadResponse(ctx, dataView)
52+
diags = stateModel.fromAPIReadResponse(ctx, maintenanceWindow)
5353
resp.Diagnostics.Append(diags...)
5454
if resp.Diagnostics.HasError() {
5555
return

internal/kibana/maintenance_window/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *MaintenanceWindowResource) Schema(_ context.Context, _ resource.SchemaR
7474
Required: true,
7575
Attributes: map[string]schema.Attribute{
7676
"end": schema.StringAttribute{
77-
Description: "The start date and time of the schedule, provided in ISO 8601 format and set to the UTC timezone. For example: `2025-03-12T12:00:00.000Z`.",
77+
Description: "The end date and time of the schedule, provided in ISO 8601 format and set to the UTC timezone. For example: `2025-03-12T12:00:00.000Z`.",
7878
Optional: true,
7979
},
8080
"every": schema.StringAttribute{

0 commit comments

Comments
 (0)