-
Notifications
You must be signed in to change notification settings - Fork 123
Add security list resource #1489
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
Changes from all commits
98dc650
9315d91
56dfc30
9c26819
f7a8fd9
708a26c
0909159
ff8f9bc
924f1d7
52c50ba
d89ae58
20b443d
87e4123
1907787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| resource "elasticstack_kibana_security_list" "ip_list" { | ||
| space_id = "default" | ||
| name = "Trusted IP Addresses" | ||
| description = "List of trusted IP addresses for security rules" | ||
| type = "ip" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "elasticstack_kibana_security_list" "keyword_list" { | ||
| space_id = "security" | ||
| list_id = "custom-keywords" | ||
| name = "Custom Keywords" | ||
| description = "Custom keyword list for detection rules" | ||
| type = "keyword" | ||
| } |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,154 @@ | ||||||
| package kibana_oapi | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "net/http" | ||||||
|
|
||||||
| "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" | ||||||
| "github.com/elastic/terraform-provider-elasticstack/internal/diagutil" | ||||||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||||||
| ) | ||||||
|
|
||||||
| // CreateListIndex creates the .lists and .items data streams for a space if they don't exist. | ||||||
| // This is required before any list operations can be performed. | ||||||
| func CreateListIndex(ctx context.Context, client *Client, spaceId string) diag.Diagnostics { | ||||||
| resp, err := client.API.CreateListIndexWithResponse(ctx, kbapi.SpaceId(spaceId)) | ||||||
| if err != nil { | ||||||
| return diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return nil | ||||||
| default: | ||||||
| return reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // GetList reads a security list from the API by ID | ||||||
| func GetList(ctx context.Context, client *Client, spaceId string, params *kbapi.ReadListParams) (*kbapi.ReadListResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.ReadListWithResponse(ctx, kbapi.SpaceId(spaceId), params) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
|
Member
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.
Suggested change
Does it make sense to return the parsed response models from these helpers?
Contributor
Author
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. I think it does. I may opt to do that refactor in the list item PR though for the sake of easily pulling these changes into that dependent PR. |
||||||
| case http.StatusNotFound: | ||||||
| return nil, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // CreateList creates a new security list. | ||||||
| func CreateList(ctx context.Context, client *Client, spaceId string, body kbapi.CreateListJSONRequestBody) (*kbapi.CreateListResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.CreateListWithResponse(ctx, kbapi.SpaceId(spaceId), body) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // UpdateList updates an existing security list. | ||||||
| func UpdateList(ctx context.Context, client *Client, spaceId string, body kbapi.UpdateListJSONRequestBody) (*kbapi.UpdateListResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.UpdateListWithResponse(ctx, kbapi.SpaceId(spaceId), body) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // DeleteList deletes an existing security list. | ||||||
| func DeleteList(ctx context.Context, client *Client, spaceId string, params *kbapi.DeleteListParams) diag.Diagnostics { | ||||||
| resp, err := client.API.DeleteListWithResponse(ctx, kbapi.SpaceId(spaceId), params) | ||||||
| if err != nil { | ||||||
| return diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return nil | ||||||
| case http.StatusNotFound: | ||||||
| return nil | ||||||
| default: | ||||||
| return reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // GetListItem reads a security list item from the API by ID or list_id and value | ||||||
| func GetListItem(ctx context.Context, client *Client, spaceId string, params *kbapi.ReadListItemParams) (*kbapi.ReadListItemResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.ReadListItemWithResponse(ctx, kbapi.SpaceId(spaceId), params) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
| case http.StatusNotFound: | ||||||
| return nil, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // CreateListItem creates a new security list item. | ||||||
| func CreateListItem(ctx context.Context, client *Client, spaceId string, body kbapi.CreateListItemJSONRequestBody) (*kbapi.CreateListItemResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.CreateListItemWithResponse(ctx, kbapi.SpaceId(spaceId), body) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // UpdateListItem updates an existing security list item. | ||||||
| func UpdateListItem(ctx context.Context, client *Client, spaceId string, body kbapi.UpdateListItemJSONRequestBody) (*kbapi.UpdateListItemResponse, diag.Diagnostics) { | ||||||
| resp, err := client.API.UpdateListItemWithResponse(ctx, kbapi.SpaceId(spaceId), body) | ||||||
| if err != nil { | ||||||
| return nil, diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return resp, nil | ||||||
| default: | ||||||
| return nil, reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // DeleteListItem deletes an existing security list item. | ||||||
| func DeleteListItem(ctx context.Context, client *Client, spaceId string, params *kbapi.DeleteListItemParams) diag.Diagnostics { | ||||||
| resp, err := client.API.DeleteListItemWithResponse(ctx, kbapi.SpaceId(spaceId), params) | ||||||
| if err != nil { | ||||||
| return diagutil.FrameworkDiagFromError(err) | ||||||
| } | ||||||
|
|
||||||
| switch resp.StatusCode() { | ||||||
| case http.StatusOK: | ||||||
| return nil | ||||||
| case http.StatusNotFound: | ||||||
| return nil | ||||||
| default: | ||||||
| return reportUnknownError(resp.StatusCode(), resp.Body) | ||||||
| } | ||||||
| } | ||||||
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.
Copilot kept suggesting that I use the create / update response instead of doing a secondary read. Adding this seems to help with that.