-
Notifications
You must be signed in to change notification settings - Fork 122
Add security exception item #1496
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4fc1308
Add security exception item resource
nick-benoit 55c730b
Merge branch 'main' of github.com:elastic/terraform-provider-elastics…
nick-benoit 807c6a3
Add resource to provider
nick-benoit 0859414
Refactor to handle new exception client helper api
nick-benoit a2a4fbe
Merge branch 'main' of github.com:elastic/terraform-provider-elastics…
nick-benoit ae4fa04
Extract create / update request building to helper in models.go
nick-benoit cf369c6
Refactor to adhere to coding standards
nick-benoit ae3bcd8
Update coding standards to include typeutils
nick-benoit 7d3df78
Add example
nick-benoit 887793f
Fix tests for tags as set
nick-benoit 308efad
Extract comment schema into helper
nick-benoit 58c4fb7
Simplify os_types handling
nick-benoit 00f815d
Add complex usage test
nick-benoit 2f006fa
Add import test
nick-benoit d307795
Add check destroy to tests
nick-benoit 1b8528f
Add resource testing standards
nick-benoit 31b2ce5
Use utils.isKnown
nick-benoit f418a73
Refactor type specific handler into their own functions
nick-benoit b9a7935
Remove unfinished entry from CODING_STANDARDS
nick-benoit 7123e60
Fix coding standards header
nick-benoit 4034088
Cleanup extraneous null checks
nick-benoit 53fa7c3
Fix tests
nick-benoit 6f7f6f2
Add compId
nick-benoit f13df88
Add expire_time to test
nick-benoit ddebd35
Remove consolidated test
nick-benoit f228296
Support agnostic namespace
nick-benoit df0dfca
Add version gate
nick-benoit 576c37f
Supprt version check for older kibanas
nick-benoit c146df6
Only set expire_time for supporting versions
nick-benoit 08d9cc5
Fmt
nick-benoit a2566cc
Remove expire_time from basic test
nick-benoit 4e4b02d
Add custom time serialization
nick-benoit bba11b9
Run tests with 8.7.2
nick-benoit 6159792
Skip tests for 8.7.1
nick-benoit dda7bf1
Add basic usage spec
nick-benoit 0652bf9
Add tests for all nested types
nick-benoit 2ae421d
Refactor nested item handling to take references
nick-benoit bfc3557
Update internal/kibana/security_exception_item/update.go
nick-benoit 321987a
Update internal/kibana/security_exception_item/create.go
nick-benoit 2936a3d
Update CODING_STANDARDS.md
nick-benoit 23f2de2
Update CODING_STANDARDS.md
nick-benoit f7fd99e
Update os_types handling
nick-benoit a4da71b
Extract shared code to setCommonProps
nick-benoit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
examples/resources/elasticstack_kibana_security_exception_item/resource.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| resource "elasticstack_kibana_security_exception_list" "example" { | ||
| list_id = "my-exception-list" | ||
| name = "My Exception List" | ||
| description = "List of exceptions" | ||
| type = "detection" | ||
| namespace_type = "single" | ||
| } | ||
|
|
||
| resource "elasticstack_kibana_security_exception_item" "complex_entry" { | ||
| list_id = elasticstack_kibana_security_exception_list.example.list_id | ||
| item_id = "complex-exception" | ||
| name = "Complex Exception with Multiple Entries" | ||
| description = "Exception with multiple conditions" | ||
| type = "simple" | ||
| namespace_type = "single" | ||
|
|
||
| # Multiple entries with different operators | ||
| entries = [ | ||
| { | ||
| type = "match" | ||
| field = "host.name" | ||
| operator = "included" | ||
| value = "trusted-host" | ||
| }, | ||
| { | ||
| type = "match_any" | ||
| field = "user.name" | ||
| operator = "excluded" | ||
| values = ["admin", "root"] | ||
| } | ||
| ] | ||
|
|
||
| os_types = ["linux"] | ||
| tags = ["complex", "multi-condition"] | ||
| } | ||
|
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package security_exception_item | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" | ||
| "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||
| ) | ||
|
|
||
| func (r *ExceptionItemResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||
| var plan ExceptionItemModel | ||
|
|
||
| diags := req.Plan.Get(ctx, &plan) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| client, err := r.client.GetKibanaOapiClient() | ||
| if err != nil { | ||
| resp.Diagnostics.AddError("Failed to get Kibana client", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| // Build the request body using model method | ||
| body, diags := plan.toCreateRequest(ctx) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| // Create the exception item | ||
| createResp, diags := kibana_oapi.CreateExceptionListItem(ctx, client, plan.SpaceID.ValueString(), *body) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| if createResp == nil { | ||
| resp.Diagnostics.AddError("Failed to create exception item", "API returned empty response") | ||
| return | ||
| } | ||
|
|
||
| /* | ||
| * In create/update paths we typically follow the write operation with a read, and then set the state from the read. | ||
| * We want to avoid a dirty plan immediately after an apply. | ||
| */ | ||
| // Read back the created resource to get the final state | ||
nick-benoit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| readParams := &kbapi.ReadExceptionListItemParams{ | ||
| Id: (*kbapi.SecurityExceptionsAPIExceptionListItemId)(&createResp.Id), | ||
| } | ||
|
|
||
| readResp, diags := kibana_oapi.GetExceptionListItem(ctx, client, plan.SpaceID.ValueString(), readParams) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| if readResp == nil { | ||
| resp.State.RemoveResource(ctx) | ||
| return | ||
| } | ||
|
|
||
| // Update state with read response using model method | ||
| diags = plan.fromAPI(ctx, readResp) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| diags = resp.State.Set(ctx, plan) | ||
| resp.Diagnostics.Append(diags...) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package security_exception_item | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" | ||
| "github.com/elastic/terraform-provider-elasticstack/internal/clients" | ||
| "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" | ||
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||
| ) | ||
|
|
||
| func (r *ExceptionItemResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { | ||
| var state ExceptionItemModel | ||
|
|
||
| diags := req.State.Get(ctx, &state) | ||
| resp.Diagnostics.Append(diags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| // Parse composite ID to get space_id and resource_id | ||
| compId, compIdDiags := clients.CompositeIdFromStrFw(state.ID.ValueString()) | ||
| resp.Diagnostics.Append(compIdDiags...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| client, err := r.client.GetKibanaOapiClient() | ||
| if err != nil { | ||
| resp.Diagnostics.AddError("Failed to get Kibana client", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| // Delete by ID | ||
| id := kbapi.SecurityExceptionsAPIExceptionListItemId(compId.ResourceId) | ||
| params := &kbapi.DeleteExceptionListItemParams{ | ||
| Id: &id, | ||
| } | ||
|
|
||
| diags = kibana_oapi.DeleteExceptionListItem(ctx, client, state.SpaceID.ValueString(), params) | ||
| resp.Diagnostics.Append(diags...) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.