Skip to content

Commit eb0b1ad

Browse files
committed
Fix linting issues and add changelog entry
1 parent ccbd16d commit eb0b1ad

File tree

10 files changed

+101
-100
lines changed

10 files changed

+101
-100
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Unreleased]
22

3+
- Create `elasticstack_kibana_security_detection_rule` resource to manage Kibana Security Detection Rules. ([#1290](https://github.com/elastic/terraform-provider-elasticstack/pull/1290))
34
- Create `elasticstack_kibana_maintenance_window` resource. ([#1224](https://github.com/elastic/terraform-provider-elasticstack/pull/1224))
45
- Add support for `solution` field in `elasticstack_kibana_space` resource and data source ([#1102](https://github.com/elastic/terraform-provider-elasticstack/issues/1102))
56
- Add `slo_id` validation to `elasticstack_kibana_slo` ([#1221](https://github.com/elastic/terraform-provider-elasticstack/pull/1221))

internal/kibana/security/detection_rule/acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ resource "elasticstack_kibana_security_detection_rule" "test" {
4545
from = "now-6m"
4646
to = "now"
4747
}`
48-
}
48+
}

internal/kibana/security/detection_rule/client.go

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,63 @@ import (
1212

1313
// SecurityDetectionRuleRequest represents a security detection rule creation/update request
1414
type SecurityDetectionRuleRequest struct {
15-
Name string `json:"name"`
16-
Description string `json:"description"`
17-
Type string `json:"type"`
18-
Query *string `json:"query,omitempty"`
19-
Language *string `json:"language,omitempty"`
20-
Index []string `json:"index,omitempty"`
21-
Severity string `json:"severity"`
22-
Risk int `json:"risk_score"`
23-
Enabled bool `json:"enabled"`
24-
Tags []string `json:"tags,omitempty"`
25-
From string `json:"from"`
26-
To string `json:"to"`
27-
Interval string `json:"interval"`
28-
Meta *map[string]any `json:"meta,omitempty"`
29-
Author []string `json:"author,omitempty"`
30-
License *string `json:"license,omitempty"`
31-
RuleNameOverride *string `json:"rule_name_override,omitempty"`
32-
TimestampOverride *string `json:"timestamp_override,omitempty"`
33-
Note *string `json:"note,omitempty"`
34-
References []string `json:"references,omitempty"`
35-
FalsePositives []string `json:"false_positives,omitempty"`
36-
ExceptionsList []any `json:"exceptions_list,omitempty"`
37-
Version int `json:"version"`
38-
MaxSignals int `json:"max_signals"`
15+
Name string `json:"name"`
16+
Description string `json:"description"`
17+
Type string `json:"type"`
18+
Query *string `json:"query,omitempty"`
19+
Language *string `json:"language,omitempty"`
20+
Index []string `json:"index,omitempty"`
21+
Severity string `json:"severity"`
22+
Risk int `json:"risk_score"`
23+
Enabled bool `json:"enabled"`
24+
Tags []string `json:"tags,omitempty"`
25+
From string `json:"from"`
26+
To string `json:"to"`
27+
Interval string `json:"interval"`
28+
Meta *map[string]any `json:"meta,omitempty"`
29+
Author []string `json:"author,omitempty"`
30+
License *string `json:"license,omitempty"`
31+
RuleNameOverride *string `json:"rule_name_override,omitempty"`
32+
TimestampOverride *string `json:"timestamp_override,omitempty"`
33+
Note *string `json:"note,omitempty"`
34+
References []string `json:"references,omitempty"`
35+
FalsePositives []string `json:"false_positives,omitempty"`
36+
ExceptionsList []any `json:"exceptions_list,omitempty"`
37+
Version int `json:"version"`
38+
MaxSignals int `json:"max_signals"`
3939
}
4040

4141
// SecurityDetectionRuleResponse represents the API response for a security detection rule
4242
type SecurityDetectionRuleResponse struct {
43-
ID string `json:"id"`
44-
Name string `json:"name"`
45-
Description string `json:"description"`
46-
Type string `json:"type"`
47-
Query *string `json:"query,omitempty"`
48-
Language *string `json:"language,omitempty"`
49-
Index []string `json:"index,omitempty"`
50-
Severity string `json:"severity"`
51-
Risk int `json:"risk_score"`
52-
Enabled bool `json:"enabled"`
53-
Tags []string `json:"tags,omitempty"`
54-
From string `json:"from"`
55-
To string `json:"to"`
56-
Interval string `json:"interval"`
57-
Meta *map[string]any `json:"meta,omitempty"`
58-
Author []string `json:"author,omitempty"`
59-
License *string `json:"license,omitempty"`
60-
RuleNameOverride *string `json:"rule_name_override,omitempty"`
61-
TimestampOverride *string `json:"timestamp_override,omitempty"`
62-
Note *string `json:"note,omitempty"`
63-
References []string `json:"references,omitempty"`
64-
FalsePositives []string `json:"false_positives,omitempty"`
65-
ExceptionsList []any `json:"exceptions_list,omitempty"`
66-
Version int `json:"version"`
67-
MaxSignals int `json:"max_signals"`
68-
CreatedAt string `json:"created_at"`
69-
CreatedBy string `json:"created_by"`
70-
UpdatedAt string `json:"updated_at"`
71-
UpdatedBy string `json:"updated_by"`
43+
ID string `json:"id"`
44+
Name string `json:"name"`
45+
Description string `json:"description"`
46+
Type string `json:"type"`
47+
Query *string `json:"query,omitempty"`
48+
Language *string `json:"language,omitempty"`
49+
Index []string `json:"index,omitempty"`
50+
Severity string `json:"severity"`
51+
Risk int `json:"risk_score"`
52+
Enabled bool `json:"enabled"`
53+
Tags []string `json:"tags,omitempty"`
54+
From string `json:"from"`
55+
To string `json:"to"`
56+
Interval string `json:"interval"`
57+
Meta *map[string]any `json:"meta,omitempty"`
58+
Author []string `json:"author,omitempty"`
59+
License *string `json:"license,omitempty"`
60+
RuleNameOverride *string `json:"rule_name_override,omitempty"`
61+
TimestampOverride *string `json:"timestamp_override,omitempty"`
62+
Note *string `json:"note,omitempty"`
63+
References []string `json:"references,omitempty"`
64+
FalsePositives []string `json:"false_positives,omitempty"`
65+
ExceptionsList []any `json:"exceptions_list,omitempty"`
66+
Version int `json:"version"`
67+
MaxSignals int `json:"max_signals"`
68+
CreatedAt string `json:"created_at"`
69+
CreatedBy string `json:"created_by"`
70+
UpdatedAt string `json:"updated_at"`
71+
UpdatedBy string `json:"updated_by"`
7272
}
7373

7474
// CreateSecurityDetectionRule creates a new security detection rule
@@ -228,4 +228,4 @@ func DeleteSecurityDetectionRule(ctx context.Context, client *clients.ApiClient,
228228
}
229229

230230
return diags
231-
}
231+
}

internal/kibana/security/detection_rule/create.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (r *securityDetectionRuleResource) Create(ctx context.Context, req resource
6262

6363
func dataToAPIRequest(ctx context.Context, data *SecurityDetectionRuleData) (*SecurityDetectionRuleRequest, diag.Diagnostics) {
6464
var diags diag.Diagnostics
65-
65+
6666
req := &SecurityDetectionRuleRequest{
6767
Name: data.Name.ValueString(),
6868
Description: data.Description.ValueString(),
@@ -248,7 +248,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
248248
}
249249

250250
// Handle arrays
251-
if result.Index != nil && len(result.Index) > 0 {
251+
if len(result.Index) > 0 {
252252
indexValues := make([]types.String, len(result.Index))
253253
for i, idx := range result.Index {
254254
indexValues[i] = types.StringValue(idx)
@@ -259,7 +259,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
259259
data.Index, _ = types.ListValueFrom(ctx, types.StringType, []types.String{types.StringValue("*")})
260260
}
261261

262-
if result.Tags != nil && len(result.Tags) > 0 {
262+
if len(result.Tags) > 0 {
263263
tagValues := make([]types.String, len(result.Tags))
264264
for i, tag := range result.Tags {
265265
tagValues[i] = types.StringValue(tag)
@@ -269,7 +269,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
269269
data.Tags, _ = types.ListValueFrom(ctx, types.StringType, []types.String{})
270270
}
271271

272-
if result.Author != nil && len(result.Author) > 0 {
272+
if len(result.Author) > 0 {
273273
authorValues := make([]types.String, len(result.Author))
274274
for i, author := range result.Author {
275275
authorValues[i] = types.StringValue(author)
@@ -279,7 +279,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
279279
data.Author, _ = types.ListValueFrom(ctx, types.StringType, []types.String{})
280280
}
281281

282-
if result.References != nil && len(result.References) > 0 {
282+
if len(result.References) > 0 {
283283
refValues := make([]types.String, len(result.References))
284284
for i, ref := range result.References {
285285
refValues[i] = types.StringValue(ref)
@@ -289,7 +289,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
289289
data.References, _ = types.ListValueFrom(ctx, types.StringType, []types.String{})
290290
}
291291

292-
if result.FalsePositives != nil && len(result.FalsePositives) > 0 {
292+
if len(result.FalsePositives) > 0 {
293293
fpValues := make([]types.String, len(result.FalsePositives))
294294
for i, fp := range result.FalsePositives {
295295
fpValues[i] = types.StringValue(fp)
@@ -299,7 +299,7 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
299299
data.FalsePositives, _ = types.ListValueFrom(ctx, types.StringType, []types.String{})
300300
}
301301

302-
if result.ExceptionsList != nil && len(result.ExceptionsList) > 0 {
302+
if len(result.ExceptionsList) > 0 {
303303
// Convert exceptions to strings (simplified)
304304
excValues := make([]types.String, len(result.ExceptionsList))
305305
for i, exc := range result.ExceptionsList {
@@ -317,4 +317,4 @@ func apiResponseToData(ctx context.Context, result *SecurityDetectionRuleRespons
317317
}
318318

319319
return diags
320-
}
320+
}

internal/kibana/security/detection_rule/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ func (r *securityDetectionRuleResource) Delete(ctx context.Context, req resource
3232
}
3333

3434
// Resource is automatically removed from state
35-
}
35+
}

internal/kibana/security/detection_rule/models.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,32 @@ import (
55
)
66

77
type SecurityDetectionRuleData struct {
8-
Id types.String `tfsdk:"id"`
9-
KibanaConnection types.List `tfsdk:"kibana_connection"`
10-
SpaceId types.String `tfsdk:"space_id"`
11-
RuleId types.String `tfsdk:"rule_id"`
12-
Name types.String `tfsdk:"name"`
13-
Description types.String `tfsdk:"description"`
14-
Type types.String `tfsdk:"type"`
15-
Query types.String `tfsdk:"query"`
16-
Language types.String `tfsdk:"language"`
17-
Index types.List `tfsdk:"index"`
18-
Severity types.String `tfsdk:"severity"`
19-
Risk types.Int64 `tfsdk:"risk"`
20-
Enabled types.Bool `tfsdk:"enabled"`
21-
Tags types.List `tfsdk:"tags"`
22-
From types.String `tfsdk:"from"`
23-
To types.String `tfsdk:"to"`
24-
Interval types.String `tfsdk:"interval"`
25-
Meta types.String `tfsdk:"meta"`
26-
Author types.List `tfsdk:"author"`
27-
License types.String `tfsdk:"license"`
28-
RuleNameOverride types.String `tfsdk:"rule_name_override"`
29-
TimestampOverride types.String `tfsdk:"timestamp_override"`
30-
Note types.String `tfsdk:"note"`
31-
References types.List `tfsdk:"references"`
32-
FalsePositives types.List `tfsdk:"false_positives"`
33-
ExceptionsList types.List `tfsdk:"exceptions_list"`
34-
Version types.Int64 `tfsdk:"version"`
35-
MaxSignals types.Int64 `tfsdk:"max_signals"`
36-
}
8+
Id types.String `tfsdk:"id"`
9+
KibanaConnection types.List `tfsdk:"kibana_connection"`
10+
SpaceId types.String `tfsdk:"space_id"`
11+
RuleId types.String `tfsdk:"rule_id"`
12+
Name types.String `tfsdk:"name"`
13+
Description types.String `tfsdk:"description"`
14+
Type types.String `tfsdk:"type"`
15+
Query types.String `tfsdk:"query"`
16+
Language types.String `tfsdk:"language"`
17+
Index types.List `tfsdk:"index"`
18+
Severity types.String `tfsdk:"severity"`
19+
Risk types.Int64 `tfsdk:"risk"`
20+
Enabled types.Bool `tfsdk:"enabled"`
21+
Tags types.List `tfsdk:"tags"`
22+
From types.String `tfsdk:"from"`
23+
To types.String `tfsdk:"to"`
24+
Interval types.String `tfsdk:"interval"`
25+
Meta types.String `tfsdk:"meta"`
26+
Author types.List `tfsdk:"author"`
27+
License types.String `tfsdk:"license"`
28+
RuleNameOverride types.String `tfsdk:"rule_name_override"`
29+
TimestampOverride types.String `tfsdk:"timestamp_override"`
30+
Note types.String `tfsdk:"note"`
31+
References types.List `tfsdk:"references"`
32+
FalsePositives types.List `tfsdk:"false_positives"`
33+
ExceptionsList types.List `tfsdk:"exceptions_list"`
34+
Version types.Int64 `tfsdk:"version"`
35+
MaxSignals types.Int64 `tfsdk:"max_signals"`
36+
}

internal/kibana/security/detection_rule/read.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *securityDetectionRuleResource) Read(ctx context.Context, req resource.R
3535
// If rule not found, remove from state
3636
if result == nil {
3737
tflog.Warn(ctx, "Security detection rule not found, removing from state", map[string]interface{}{
38-
"rule_id": ruleId,
38+
"rule_id": ruleId,
3939
"space_id": spaceId,
4040
})
4141
resp.State.RemoveResource(ctx)
@@ -49,8 +49,8 @@ func (r *securityDetectionRuleResource) Read(ctx context.Context, req resource.R
4949
return
5050
}
5151

52-
// Set space_id from the composite ID
53-
data.SpaceId = data.SpaceId // Keep the original value from config
52+
// Set space_id from the composite ID (keep existing value from config)
53+
// data.SpaceId remains unchanged
5454

5555
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
56-
}
56+
}

internal/kibana/security/detection_rule/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ func (r *securityDetectionRuleResource) Configure(_ context.Context, req resourc
2323
client, diags := clients.ConvertProviderData(req.ProviderData)
2424
resp.Diagnostics.Append(diags...)
2525
r.client = client
26-
}
26+
}

internal/kibana/security/detection_rule/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@ func GetSchema() schema.Schema {
197197
},
198198
},
199199
}
200-
}
200+
}

internal/kibana/security/detection_rule/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ func (r *securityDetectionRuleResource) Update(ctx context.Context, req resource
4646
}
4747

4848
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
49-
}
49+
}

0 commit comments

Comments
 (0)