Skip to content

Commit 8815af2

Browse files
Copilotnick-benoit
andcommitted
Add exception_list and exception_item resources with CRUD operations
Co-authored-by: nick-benoit <[email protected]>
1 parent bfd68f8 commit 8815af2

File tree

20 files changed

+1614
-0
lines changed

20 files changed

+1614
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "elasticstack_kibana_security_exception_item Resource - terraform-provider-elasticstack"
4+
subcategory: "Kibana"
5+
description: |-
6+
Manages a Kibana Exception Item. Exception items define the specific query conditions used to prevent rules from generating alerts.
7+
See the Kibana Exceptions API documentation https://www.elastic.co/docs/api/doc/kibana/group/endpoint-security-exceptions-api for more details.
8+
Example Usage
9+
10+
resource "elasticstack_kibana_security_exception_item" "example" {
11+
list_id = elasticstack_kibana_security_exception_list.example.list_id
12+
item_id = "my-exception-item"
13+
name = "My Exception Item"
14+
description = "Exclude specific processes from alerts"
15+
type = "simple"
16+
namespace_type = "single"
17+
18+
entries = jsonencode([
19+
{
20+
field = "process.name"
21+
operator = "included"
22+
type = "match"
23+
value = "my-process"
24+
}
25+
])
26+
27+
tags = ["tag1", "tag2"]
28+
}
29+
---
30+
31+
# elasticstack_kibana_security_exception_item (Resource)
32+
33+
Manages a Kibana Exception Item. Exception items define the specific query conditions used to prevent rules from generating alerts.
34+
35+
See the [Kibana Exceptions API documentation](https://www.elastic.co/docs/api/doc/kibana/group/endpoint-security-exceptions-api) for more details.
36+
37+
## Example Usage
38+
39+
```terraform
40+
resource "elasticstack_kibana_security_exception_item" "example" {
41+
list_id = elasticstack_kibana_security_exception_list.example.list_id
42+
item_id = "my-exception-item"
43+
name = "My Exception Item"
44+
description = "Exclude specific processes from alerts"
45+
type = "simple"
46+
namespace_type = "single"
47+
48+
entries = jsonencode([
49+
{
50+
field = "process.name"
51+
operator = "included"
52+
type = "match"
53+
value = "my-process"
54+
}
55+
])
56+
57+
tags = ["tag1", "tag2"]
58+
}
59+
```
60+
61+
62+
63+
<!-- schema generated by tfplugindocs -->
64+
## Schema
65+
66+
### Required
67+
68+
- `description` (String) Describes the exception item.
69+
- `entries` (String) The exception item entries as JSON string. This defines the conditions under which the exception applies.
70+
- `list_id` (String) The exception list's identifier that this item belongs to.
71+
- `name` (String) The name of the exception item.
72+
- `type` (String) The type of exception item. Must be `simple`.
73+
74+
### Optional
75+
76+
- `comments` (Attributes List) Array of comments about the exception item. (see [below for nested schema](#nestedatt--comments))
77+
- `expire_time` (String) The exception item's expiration date in ISO format. This field is only available for regular exception items, not endpoint exceptions.
78+
- `item_id` (String) The exception item's human readable string identifier.
79+
- `meta` (String) Placeholder for metadata about the exception item as JSON string.
80+
- `namespace_type` (String) Determines whether the exception item is available in all Kibana spaces or just the space in which it is created. Can be `single` (default) or `agnostic`.
81+
- `os_types` (List of String) Array of OS types for which the exceptions apply. Valid values: `linux`, `macos`, `windows`.
82+
- `tags` (List of String) String array containing words and phrases to help categorize exception items.
83+
84+
### Read-Only
85+
86+
- `created_at` (String) The timestamp of when the exception item was created.
87+
- `created_by` (String) The user who created the exception item.
88+
- `id` (String) The unique identifier of the exception item (auto-generated by Kibana).
89+
- `tie_breaker_id` (String) Field used in search to ensure all items are sorted and returned correctly.
90+
- `updated_at` (String) The timestamp of when the exception item was last updated.
91+
- `updated_by` (String) The user who last updated the exception item.
92+
93+
<a id="nestedatt--comments"></a>
94+
### Nested Schema for `comments`
95+
96+
Required:
97+
98+
- `comment` (String) The comment text.
99+
100+
Read-Only:
101+
102+
- `id` (String) The unique identifier of the comment (auto-generated by Kibana).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "elasticstack_kibana_security_exception_list Resource - terraform-provider-elasticstack"
4+
subcategory: "Kibana"
5+
description: |-
6+
Manages a Kibana Exception List. Exception lists are containers for exception items used to prevent security rules from generating alerts.
7+
See the Kibana Exceptions API documentation https://www.elastic.co/docs/api/doc/kibana/group/endpoint-security-exceptions-api for more details.
8+
Example Usage
9+
10+
resource "elasticstack_kibana_security_exception_list" "example" {
11+
list_id = "my-exception-list"
12+
name = "My Exception List"
13+
description = "List of exceptions for security rules"
14+
type = "detection"
15+
namespace_type = "single"
16+
17+
tags = ["tag1", "tag2"]
18+
}
19+
---
20+
21+
# elasticstack_kibana_security_exception_list (Resource)
22+
23+
Manages a Kibana Exception List. Exception lists are containers for exception items used to prevent security rules from generating alerts.
24+
25+
See the [Kibana Exceptions API documentation](https://www.elastic.co/docs/api/doc/kibana/group/endpoint-security-exceptions-api) for more details.
26+
27+
## Example Usage
28+
29+
```terraform
30+
resource "elasticstack_kibana_security_exception_list" "example" {
31+
list_id = "my-exception-list"
32+
name = "My Exception List"
33+
description = "List of exceptions for security rules"
34+
type = "detection"
35+
namespace_type = "single"
36+
37+
tags = ["tag1", "tag2"]
38+
}
39+
```
40+
41+
42+
43+
<!-- schema generated by tfplugindocs -->
44+
## Schema
45+
46+
### Required
47+
48+
- `description` (String) Describes the exception list.
49+
- `list_id` (String) The exception list's human readable string identifier.
50+
- `name` (String) The name of the exception list.
51+
- `type` (String) The type of exception list. Can be one of: `detection`, `endpoint`, `endpoint_trusted_apps`, `endpoint_events`, `endpoint_host_isolation_exceptions`, `endpoint_blocklists`.
52+
53+
### Optional
54+
55+
- `meta` (String) Placeholder for metadata about the list container as JSON string.
56+
- `namespace_type` (String) Determines whether the exception list is available in all Kibana spaces or just the space in which it is created. Can be `single` (default) or `agnostic`.
57+
- `os_types` (List of String) Array of OS types for which the exceptions apply. Valid values: `linux`, `macos`, `windows`.
58+
- `tags` (List of String) String array containing words and phrases to help categorize exception containers.
59+
60+
### Read-Only
61+
62+
- `created_at` (String) The timestamp of when the exception list was created.
63+
- `created_by` (String) The user who created the exception list.
64+
- `id` (String) The unique identifier of the exception list (auto-generated by Kibana).
65+
- `immutable` (Boolean) Whether the exception list is immutable.
66+
- `tie_breaker_id` (String) Field used in search to ensure all containers are sorted and returned correctly.
67+
- `updated_at` (String) The timestamp of when the exception list was last updated.
68+
- `updated_by` (String) The user who last updated the exception list.
69+
- `version` (Number) The version of the exception list.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package kibana_oapi
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
8+
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
9+
"github.com/hashicorp/terraform-plugin-framework/diag"
10+
)
11+
12+
// GetExceptionList reads an exception list from the API by ID or list_id
13+
func GetExceptionList(ctx context.Context, client *Client, params *kbapi.ReadExceptionListParams) (*kbapi.ReadExceptionListResponse, diag.Diagnostics) {
14+
resp, err := client.API.ReadExceptionListWithResponse(ctx, params)
15+
if err != nil {
16+
return nil, diagutil.FrameworkDiagFromError(err)
17+
}
18+
19+
switch resp.StatusCode() {
20+
case http.StatusOK:
21+
return resp, nil
22+
case http.StatusNotFound:
23+
return nil, nil
24+
default:
25+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
26+
}
27+
}
28+
29+
// CreateExceptionList creates a new exception list.
30+
func CreateExceptionList(ctx context.Context, client *Client, body kbapi.CreateExceptionListJSONRequestBody) (*kbapi.CreateExceptionListResponse, diag.Diagnostics) {
31+
resp, err := client.API.CreateExceptionListWithResponse(ctx, body)
32+
if err != nil {
33+
return nil, diagutil.FrameworkDiagFromError(err)
34+
}
35+
36+
switch resp.StatusCode() {
37+
case http.StatusOK:
38+
return resp, nil
39+
default:
40+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
41+
}
42+
}
43+
44+
// UpdateExceptionList updates an existing exception list.
45+
func UpdateExceptionList(ctx context.Context, client *Client, body kbapi.UpdateExceptionListJSONRequestBody) (*kbapi.UpdateExceptionListResponse, diag.Diagnostics) {
46+
resp, err := client.API.UpdateExceptionListWithResponse(ctx, body)
47+
if err != nil {
48+
return nil, diagutil.FrameworkDiagFromError(err)
49+
}
50+
51+
switch resp.StatusCode() {
52+
case http.StatusOK:
53+
return resp, nil
54+
default:
55+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
56+
}
57+
}
58+
59+
// DeleteExceptionList deletes an existing exception list.
60+
func DeleteExceptionList(ctx context.Context, client *Client, params *kbapi.DeleteExceptionListParams) diag.Diagnostics {
61+
resp, err := client.API.DeleteExceptionListWithResponse(ctx, params)
62+
if err != nil {
63+
return diagutil.FrameworkDiagFromError(err)
64+
}
65+
66+
switch resp.StatusCode() {
67+
case http.StatusOK:
68+
return nil
69+
case http.StatusNotFound:
70+
return nil
71+
default:
72+
return reportUnknownError(resp.StatusCode(), resp.Body)
73+
}
74+
}
75+
76+
// GetExceptionListItem reads an exception list item from the API by ID or item_id
77+
func GetExceptionListItem(ctx context.Context, client *Client, params *kbapi.ReadExceptionListItemParams) (*kbapi.ReadExceptionListItemResponse, diag.Diagnostics) {
78+
resp, err := client.API.ReadExceptionListItemWithResponse(ctx, params)
79+
if err != nil {
80+
return nil, diagutil.FrameworkDiagFromError(err)
81+
}
82+
83+
switch resp.StatusCode() {
84+
case http.StatusOK:
85+
return resp, nil
86+
case http.StatusNotFound:
87+
return nil, nil
88+
default:
89+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
90+
}
91+
}
92+
93+
// CreateExceptionListItem creates a new exception list item.
94+
func CreateExceptionListItem(ctx context.Context, client *Client, body kbapi.CreateExceptionListItemJSONRequestBody) (*kbapi.CreateExceptionListItemResponse, diag.Diagnostics) {
95+
resp, err := client.API.CreateExceptionListItemWithResponse(ctx, body)
96+
if err != nil {
97+
return nil, diagutil.FrameworkDiagFromError(err)
98+
}
99+
100+
switch resp.StatusCode() {
101+
case http.StatusOK:
102+
return resp, nil
103+
default:
104+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
105+
}
106+
}
107+
108+
// UpdateExceptionListItem updates an existing exception list item.
109+
func UpdateExceptionListItem(ctx context.Context, client *Client, body kbapi.UpdateExceptionListItemJSONRequestBody) (*kbapi.UpdateExceptionListItemResponse, diag.Diagnostics) {
110+
resp, err := client.API.UpdateExceptionListItemWithResponse(ctx, body)
111+
if err != nil {
112+
return nil, diagutil.FrameworkDiagFromError(err)
113+
}
114+
115+
switch resp.StatusCode() {
116+
case http.StatusOK:
117+
return resp, nil
118+
default:
119+
return nil, reportUnknownError(resp.StatusCode(), resp.Body)
120+
}
121+
}
122+
123+
// DeleteExceptionListItem deletes an existing exception list item.
124+
func DeleteExceptionListItem(ctx context.Context, client *Client, params *kbapi.DeleteExceptionListItemParams) diag.Diagnostics {
125+
resp, err := client.API.DeleteExceptionListItemWithResponse(ctx, params)
126+
if err != nil {
127+
return diagutil.FrameworkDiagFromError(err)
128+
}
129+
130+
switch resp.StatusCode() {
131+
case http.StatusOK:
132+
return nil
133+
case http.StatusNotFound:
134+
return nil
135+
default:
136+
return reportUnknownError(resp.StatusCode(), resp.Body)
137+
}
138+
}

0 commit comments

Comments
 (0)