Skip to content

Commit 0d2f463

Browse files
committed
formatting
1 parent 0de9d5c commit 0d2f463

File tree

6 files changed

+128
-20
lines changed

6 files changed

+128
-20
lines changed

generated/alerting/api_alerting_mocks.go

Lines changed: 92 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/alerting/model_notify_when_action.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/clients/kibana/alerting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func ruleActionsToActionsInner(ruleActions []models.AlertingRuleAction) []alerti
110110
if !alerting.IsNil(action.Frequency) {
111111
frequency := alerting.ActionsInnerFrequency{
112112
Summary: action.Frequency.Summary,
113-
NotifyWhen: (alerting.NotifyWhen)(action.Frequency.NotifyWhen),
113+
NotifyWhen: (alerting.NotifyWhenAction)(action.Frequency.NotifyWhen),
114114
}
115115

116116
if action.Frequency.Throttle != nil {

internal/clients/kibana/maintenance_window.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func maintenanceWindowResponseToModel(res *alerting.MaintenanceWindowResponsePro
1919
}
2020

2121
return &models.MaintenanceWindow{
22+
Id: res.Id,
2223
Title: res.Title,
2324
Enabled: res.Enabled,
2425
Start: res.Start,

internal/kibana/maintenance_window.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func ResourceMaintenanceWindow() *schema.Resource {
1515
apikeySchema := map[string]*schema.Schema{
16-
"maintenance_window_id": {
16+
"id": {
1717
Description: "A UUID v1 or v4 to use instead of a randomly generated ID.",
1818
Type: schema.TypeString,
1919
Computed: true,
@@ -48,7 +48,7 @@ func ResourceMaintenanceWindow() *schema.Resource {
4848
Description: "Creates a Kibana Maintenance Window.",
4949

5050
CreateContext: resourceMaintenanceWindowCreate,
51-
// UpdateContext: resourceMaintenanceWindowUpdate,
51+
UpdateContext: resourceMaintenanceWindowUpdate,
5252
ReadContext: resourceMaintenanceWindowRead,
5353
DeleteContext: resourceMaintenanceWindowDelete,
5454

@@ -63,16 +63,15 @@ func ResourceMaintenanceWindow() *schema.Resource {
6363
func getMaintenanceWindowFromResourceData(d *schema.ResourceData, serverVersion *version.Version) (models.MaintenanceWindow, diag.Diagnostics) {
6464
var diags diag.Diagnostics
6565
maintenanceWindow := models.MaintenanceWindow{
66-
MaintenanceWindowID: d.Get("maintenance_window_id").(string),
67-
Title: d.Get("title").(string),
68-
Enabled: d.Get("enabled").(bool),
69-
Start: d.Get("start").(string),
70-
Duration: d.Get("duration").(int),
66+
Title: d.Get("title").(string),
67+
Enabled: d.Get("enabled").(bool),
68+
Start: d.Get("start").(string),
69+
Duration: d.Get("duration").(int),
7170
}
7271

7372
// Explicitly set maintenance window id if provided, otherwise we'll use the autogenerated ID from the Kibana API response
74-
if maintenanceWindowID := getOrNilString("MaintenanceWindowID", d); maintenanceWindowID != nil && *maintenanceWindowID != "" {
75-
maintenanceWindow.MaintenanceWindowID = *maintenanceWindowID
73+
if maintenanceWindowID := getOrNilString("id", d); maintenanceWindowID != nil && *maintenanceWindowID != "" {
74+
maintenanceWindow.Id = *maintenanceWindowID
7675
}
7776

7877
return maintenanceWindow, diags
@@ -105,13 +104,37 @@ func resourceMaintenanceWindowCreate(ctx context.Context, d *schema.ResourceData
105104
return resourceRuleRead(ctx, d, meta)
106105
}
107106

107+
func resourceMaintenanceWindowUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
108+
client, diags := clients.NewApiClientFromSDKResource(d, meta)
109+
if diags.HasError() {
110+
return diags
111+
}
112+
113+
serverVersion, diags := client.ServerVersion(ctx)
114+
if diags.HasError() {
115+
return diags
116+
}
117+
118+
maintenanceWindow, diags := getMaintenanceWindowFromResourceData(d, serverVersion)
119+
if diags.HasError() {
120+
return diags
121+
}
122+
123+
// DO NOTHING
124+
// res, diags := kibana.UpdateAlertingRule(ctx, client, maintenanceWindow)
125+
d.SetId(maintenanceWindow.MaintenanceWindowID)
126+
127+
return resourceRuleRead(ctx, d, meta)
128+
}
129+
108130
func resourceMaintenanceWindowRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
109131
client, diags := clients.NewApiClientFromSDKResource(d, meta)
110132
if diags.HasError() {
111133
return diags
112134
}
113135

114136
maintenanceWindow, diags := kibana.GetMaintenanceWindow(ctx, client, d.Id())
137+
115138
if maintenanceWindow == nil && diags == nil {
116139
d.SetId("")
117140
return diags
@@ -121,7 +144,7 @@ func resourceMaintenanceWindowRead(ctx context.Context, d *schema.ResourceData,
121144
}
122145

123146
// set the fields
124-
if err := d.Set("maintenance_window_id", maintenanceWindow.MaintenanceWindowID); err != nil {
147+
if err := d.Set("id", maintenanceWindow.Id); err != nil {
125148
return diag.FromErr(err)
126149
}
127150
if err := d.Set("title", maintenanceWindow.Title); err != nil {

internal/models/maintenance_window.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
type MaintenanceWindow struct {
4+
Id string
45
MaintenanceWindowID string
56
Title string
67
Enabled bool

0 commit comments

Comments
 (0)