Skip to content

Commit 60c005b

Browse files
committed
Change float32s to int32s
1 parent 8591335 commit 60c005b

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

internal/kibana/maintenance_window/models.go

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ type MaintenanceWindowSchedule struct {
3434
}
3535

3636
type MaintenanceWindowScheduleRecurring struct {
37-
End types.String `tfsdk:"end"`
38-
Every types.String `tfsdk:"every"`
39-
Occurrences types.Float32 `tfsdk:"occurrences"`
40-
OnWeekDay types.List `tfsdk:"on_week_day"`
41-
OnMonthDay types.List `tfsdk:"on_month_day"`
42-
OnMonth types.List `tfsdk:"on_month"`
37+
End types.String `tfsdk:"end"`
38+
Every types.String `tfsdk:"every"`
39+
Occurrences types.Int32 `tfsdk:"occurrences"`
40+
OnWeekDay types.List `tfsdk:"on_week_day"`
41+
OnMonthDay types.List `tfsdk:"on_month_day"`
42+
OnMonth types.List `tfsdk:"on_month"`
4343
}
4444

4545
/* CREATE */
@@ -73,8 +73,9 @@ func (model MaintenanceWindowModel) toAPICreateRequest(ctx context.Context) (kba
7373
Every: model.CustomSchedule.Recurring.Every.ValueStringPointer(),
7474
}
7575

76-
if !model.CustomSchedule.Recurring.Occurrences.IsNull() && !model.CustomSchedule.Recurring.Occurrences.IsUnknown() && model.CustomSchedule.Recurring.Occurrences.ValueFloat32() > 0 {
77-
body.Schedule.Custom.Recurring.Occurrences = model.CustomSchedule.Recurring.Occurrences.ValueFloat32Pointer()
76+
if !model.CustomSchedule.Recurring.Occurrences.IsNull() && !model.CustomSchedule.Recurring.Occurrences.IsUnknown() && model.CustomSchedule.Recurring.Occurrences.ValueInt32() > 0 {
77+
occurrences := float32(model.CustomSchedule.Recurring.Occurrences.ValueInt32())
78+
body.Schedule.Custom.Recurring.Occurrences = &occurrences
7879
}
7980

8081
if !model.CustomSchedule.Recurring.OnWeekDay.IsNull() && !model.CustomSchedule.Recurring.OnWeekDay.IsUnknown() {
@@ -148,12 +149,16 @@ func (model *MaintenanceWindowModel) fromAPICreateResponse(ctx context.Context,
148149

149150
if response.Schedule.Custom.Recurring != nil {
150151
model.CustomSchedule.Recurring = &MaintenanceWindowScheduleRecurring{
151-
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
152-
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
153-
Occurrences: types.Float32PointerValue(response.Schedule.Custom.Recurring.Occurrences),
154-
OnWeekDay: types.ListNull(types.StringType),
155-
OnMonth: types.ListNull(types.Float32Type),
156-
OnMonthDay: types.ListNull(types.Float32Type),
152+
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
153+
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
154+
OnWeekDay: types.ListNull(types.StringType),
155+
OnMonth: types.ListNull(types.Int32Type),
156+
OnMonthDay: types.ListNull(types.Int32Type),
157+
}
158+
159+
if response.Schedule.Custom.Recurring.Occurrences != nil {
160+
occurrences := int32(*response.Schedule.Custom.Recurring.Occurrences)
161+
model.CustomSchedule.Recurring.Occurrences = types.Int32PointerValue(&occurrences)
157162
}
158163

159164
if response.Schedule.Custom.Recurring.OnWeekDay != nil {
@@ -211,12 +216,16 @@ func (model *MaintenanceWindowModel) fromAPIReadResponse(ctx context.Context, da
211216

212217
if response.Schedule.Custom.Recurring != nil {
213218
model.CustomSchedule.Recurring = &MaintenanceWindowScheduleRecurring{
214-
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
215-
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
216-
Occurrences: types.Float32PointerValue(response.Schedule.Custom.Recurring.Occurrences),
217-
OnWeekDay: types.ListNull(types.StringType),
218-
OnMonth: types.ListNull(types.Float32Type),
219-
OnMonthDay: types.ListNull(types.Float32Type),
219+
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
220+
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
221+
OnWeekDay: types.ListNull(types.StringType),
222+
OnMonth: types.ListNull(types.Float32Type),
223+
OnMonthDay: types.ListNull(types.Float32Type),
224+
}
225+
226+
if response.Schedule.Custom.Recurring.Occurrences != nil {
227+
occurrences := int32(*response.Schedule.Custom.Recurring.Occurrences)
228+
model.CustomSchedule.Recurring.Occurrences = types.Int32PointerValue(&occurrences)
220229
}
221230

222231
if response.Schedule.Custom.Recurring.OnWeekDay != nil {
@@ -319,8 +328,9 @@ func (model MaintenanceWindowModel) toAPIUpdateRequest(ctx context.Context) (kba
319328
body.Schedule.Custom.Recurring.Every = model.CustomSchedule.Recurring.Every.ValueStringPointer()
320329
}
321330

322-
if !model.CustomSchedule.Recurring.Occurrences.IsNull() && !model.CustomSchedule.Recurring.Occurrences.IsUnknown() && model.CustomSchedule.Recurring.Occurrences.ValueFloat32() > 0 {
323-
body.Schedule.Custom.Recurring.Occurrences = model.CustomSchedule.Recurring.Occurrences.ValueFloat32Pointer()
331+
if !model.CustomSchedule.Recurring.Occurrences.IsNull() && !model.CustomSchedule.Recurring.Occurrences.IsUnknown() && model.CustomSchedule.Recurring.Occurrences.ValueInt32() > 0 {
332+
occurrences := float32(model.CustomSchedule.Recurring.Occurrences.ValueInt32())
333+
body.Schedule.Custom.Recurring.Occurrences = &occurrences
324334
}
325335

326336
if !model.CustomSchedule.Recurring.OnWeekDay.IsNull() && !model.CustomSchedule.Recurring.OnWeekDay.IsUnknown() {
@@ -368,7 +378,7 @@ func (model MaintenanceWindowModel) toAPIUpdateRequest(ctx context.Context) (kba
368378
return body, diags
369379
}
370380

371-
func (model *MaintenanceWindowModel) fromAPIUpdateResponse(ctx context.Context, data *kbapi.PatchMaintenanceWindowIdResponse, spaceID string) diag.Diagnostics {
381+
func (model *MaintenanceWindowModel) fromAPIUpdateResponse(ctx context.Context, data *kbapi.PatchMaintenanceWindowIdResponse) diag.Diagnostics {
372382
if data == nil {
373383
return nil
374384
}
@@ -394,12 +404,16 @@ func (model *MaintenanceWindowModel) fromAPIUpdateResponse(ctx context.Context,
394404

395405
if response.Schedule.Custom.Recurring != nil {
396406
model.CustomSchedule.Recurring = &MaintenanceWindowScheduleRecurring{
397-
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
398-
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
399-
Occurrences: types.Float32PointerValue(response.Schedule.Custom.Recurring.Occurrences),
400-
OnWeekDay: types.ListNull(types.StringType),
401-
OnMonth: types.ListNull(types.Float32Type),
402-
OnMonthDay: types.ListNull(types.Float32Type),
407+
End: types.StringPointerValue(response.Schedule.Custom.Recurring.End),
408+
Every: types.StringPointerValue(response.Schedule.Custom.Recurring.Every),
409+
OnWeekDay: types.ListNull(types.StringType),
410+
OnMonth: types.ListNull(types.Float32Type),
411+
OnMonthDay: types.ListNull(types.Float32Type),
412+
}
413+
414+
if response.Schedule.Custom.Recurring.Occurrences != nil {
415+
occurrences := int32(*response.Schedule.Custom.Recurring.Occurrences)
416+
model.CustomSchedule.Recurring.Occurrences = types.Int32PointerValue(&occurrences)
403417
}
404418

405419
if response.Schedule.Custom.Recurring.OnWeekDay != nil {

internal/kibana/maintenance_window/schema.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package maintenance_window
33
import (
44
"context"
55

6-
"github.com/hashicorp/terraform-plugin-framework-validators/float32validator"
6+
"github.com/hashicorp/terraform-plugin-framework-validators/int32validator"
77
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
88
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
99
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -84,11 +84,11 @@ func (r *MaintenanceWindowResource) Schema(_ context.Context, _ resource.SchemaR
8484
StringIsMaintenanceWindowIntervalFrequency{},
8585
},
8686
},
87-
"occurrences": schema.Float32Attribute{
87+
"occurrences": schema.Int32Attribute{
8888
Description: "The total number of recurrences of the schedule.",
8989
Optional: true,
90-
Validators: []validator.Float32{
91-
float32validator.AtLeast(1),
90+
Validators: []validator.Int32{
91+
int32validator.AtLeast(1),
9292
},
9393
},
9494
"on_week_day": schema.ListAttribute{
@@ -103,21 +103,21 @@ func (r *MaintenanceWindowResource) Schema(_ context.Context, _ resource.SchemaR
103103
},
104104
"on_month_day": schema.ListAttribute{
105105
Description: "The specific days of the month for a recurring schedule. Valid values are 1-31.",
106-
ElementType: types.Float32Type,
106+
ElementType: types.Int32Type,
107107
Optional: true,
108108
Validators: []validator.List{
109-
listvalidator.ValueFloat32sAre(
110-
float32validator.Between(1, 31),
109+
listvalidator.ValueInt32sAre(
110+
int32validator.Between(1, 31),
111111
),
112112
},
113113
},
114114
"on_month": schema.ListAttribute{
115115
Description: "The specific months for a recurring schedule. Valid values are 1-12.",
116-
ElementType: types.Float32Type,
116+
ElementType: types.Int32Type,
117117
Optional: true,
118118
Validators: []validator.List{
119-
listvalidator.ValueFloat32sAre(
120-
float32validator.Between(1, 12),
119+
listvalidator.ValueInt32sAre(
120+
int32validator.Between(1, 12),
121121
),
122122
},
123123
},

internal/kibana/maintenance_window/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *MaintenanceWindowResource) Update(ctx context.Context, req resource.Upd
3535
return
3636
}
3737

38-
diags = planMaintenanceWindow.fromAPIUpdateResponse(ctx, maintenanceWindow, spaceID)
38+
diags = planMaintenanceWindow.fromAPIUpdateResponse(ctx, maintenanceWindow)
3939
resp.Diagnostics.Append(diags...)
4040
if resp.Diagnostics.HasError() {
4141
return

0 commit comments

Comments
 (0)