-
Notifications
You must be signed in to change notification settings - Fork 106
[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
base: main
Are you sure you want to change the base?
Changes from 1 commit
0de9d5c
0d2f463
7a7921a
867da54
42a71d9
5c38ef7
2113704
fcec64a
bf84803
2a65569
0c8422f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import ( | |
|
||
func ResourceMaintenanceWindow() *schema.Resource { | ||
apikeySchema := map[string]*schema.Schema{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like this wasn't generated but implemented by you. If so, couldn't this be generated based on the OAS files we create on the Kibana side? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The generation is only for the API client, so the resource specification is usually done manually. Maybe there is a way but I don't think we use it in this project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hashicorp have an openapi generator which builds a schema based on a set of openapi routes. It's not used in this project yet, but we're using it to help with Serverless project resources. It's... ok, but has some limitations to deal with. |
||
"maintenance_window_id": { | ||
"id": { | ||
Description: "A UUID v1 or v4 to use instead of a randomly generated ID.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
|
@@ -48,7 +48,7 @@ func ResourceMaintenanceWindow() *schema.Resource { | |
Description: "Creates a Kibana Maintenance Window.", | ||
|
||
CreateContext: resourceMaintenanceWindowCreate, | ||
// UpdateContext: resourceMaintenanceWindowUpdate, | ||
UpdateContext: resourceMaintenanceWindowUpdate, | ||
ReadContext: resourceMaintenanceWindowRead, | ||
DeleteContext: resourceMaintenanceWindowDelete, | ||
|
||
|
@@ -63,16 +63,15 @@ func ResourceMaintenanceWindow() *schema.Resource { | |
func getMaintenanceWindowFromResourceData(d *schema.ResourceData, serverVersion *version.Version) (models.MaintenanceWindow, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
maintenanceWindow := models.MaintenanceWindow{ | ||
MaintenanceWindowID: d.Get("maintenance_window_id").(string), | ||
Title: d.Get("title").(string), | ||
Enabled: d.Get("enabled").(bool), | ||
Start: d.Get("start").(string), | ||
Duration: d.Get("duration").(int), | ||
Title: d.Get("title").(string), | ||
Enabled: d.Get("enabled").(bool), | ||
Start: d.Get("start").(string), | ||
Duration: d.Get("duration").(int), | ||
} | ||
|
||
// Explicitly set maintenance window id if provided, otherwise we'll use the autogenerated ID from the Kibana API response | ||
if maintenanceWindowID := getOrNilString("MaintenanceWindowID", d); maintenanceWindowID != nil && *maintenanceWindowID != "" { | ||
maintenanceWindow.MaintenanceWindowID = *maintenanceWindowID | ||
if maintenanceWindowID := getOrNilString("id", d); maintenanceWindowID != nil && *maintenanceWindowID != "" { | ||
maintenanceWindow.Id = *maintenanceWindowID | ||
} | ||
|
||
return maintenanceWindow, diags | ||
|
@@ -105,13 +104,37 @@ func resourceMaintenanceWindowCreate(ctx context.Context, d *schema.ResourceData | |
return resourceRuleRead(ctx, d, meta) | ||
} | ||
|
||
func resourceMaintenanceWindowUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client, diags := clients.NewApiClientFromSDKResource(d, meta) | ||
if diags.HasError() { | ||
return diags | ||
} | ||
|
||
serverVersion, diags := client.ServerVersion(ctx) | ||
if diags.HasError() { | ||
return diags | ||
} | ||
|
||
maintenanceWindow, diags := getMaintenanceWindowFromResourceData(d, serverVersion) | ||
if diags.HasError() { | ||
return diags | ||
} | ||
|
||
// DO NOTHING | ||
// res, diags := kibana.UpdateAlertingRule(ctx, client, maintenanceWindow) | ||
d.SetId(maintenanceWindow.MaintenanceWindowID) | ||
|
||
return resourceRuleRead(ctx, d, meta) | ||
} | ||
|
||
func resourceMaintenanceWindowRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client, diags := clients.NewApiClientFromSDKResource(d, meta) | ||
if diags.HasError() { | ||
return diags | ||
} | ||
|
||
maintenanceWindow, diags := kibana.GetMaintenanceWindow(ctx, client, d.Id()) | ||
|
||
if maintenanceWindow == nil && diags == nil { | ||
d.SetId("") | ||
return diags | ||
|
@@ -121,7 +144,7 @@ func resourceMaintenanceWindowRead(ctx context.Context, d *schema.ResourceData, | |
} | ||
|
||
// set the fields | ||
if err := d.Set("maintenance_window_id", maintenanceWindow.MaintenanceWindowID); err != nil { | ||
if err := d.Set("id", maintenanceWindow.Id); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("title", maintenanceWindow.Title); err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package models | ||
|
||
type MaintenanceWindow struct { | ||
Id string | ||
MaintenanceWindowID string | ||
Title string | ||
Enabled bool | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rebuild this as a plugin-framework based resource (data view as an example). It automatically solves a bunch of TF related limitations, and should be the future for any new work in the provider.