Skip to content

Commit 216089e

Browse files
Copilotnick-benoit
andcommitted
Fix acceptance test failures: add Type field to update and use jsontypes.Normalized for entries
- Add missing Type field to exception_list update operation - Change entries field to use jsontypes.Normalized to handle JSON key ordering differences - This fixes the "received ''" error and "inconsistent result" errors in acceptance tests Co-authored-by: nick-benoit <[email protected]>
1 parent c84195f commit 216089e

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

internal/kibana/security/exception_item/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
99
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
1010
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
11+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1112
"github.com/hashicorp/terraform-plugin-framework/attr"
1213
"github.com/hashicorp/terraform-plugin-framework/diag"
1314
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -224,13 +225,13 @@ func (r *ExceptionItemResource) updateStateFromAPIResponse(ctx context.Context,
224225
model.Meta = types.StringNull()
225226
}
226227

227-
// Set entries (convert back to JSON)
228+
// Set entries (convert back to JSON and normalize)
228229
entriesJSON, err := json.Marshal(apiResp.Entries)
229230
if err != nil {
230231
diags.AddError("Failed to serialize entries", err.Error())
231232
return diags
232233
}
233-
model.Entries = types.StringValue(string(entriesJSON))
234+
model.Entries = jsontypes.NewNormalizedValue(string(entriesJSON))
234235

235236
// Set optional comments
236237
if len(apiResp.Comments) > 0 {

internal/kibana/security/exception_item/models.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package exception_item
22

33
import (
4+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
45
"github.com/hashicorp/terraform-plugin-framework/types"
56
)
67

78
type ExceptionItemModel struct {
8-
ID types.String `tfsdk:"id"`
9-
ItemID types.String `tfsdk:"item_id"`
10-
ListID types.String `tfsdk:"list_id"`
11-
Name types.String `tfsdk:"name"`
12-
Description types.String `tfsdk:"description"`
13-
Type types.String `tfsdk:"type"`
14-
NamespaceType types.String `tfsdk:"namespace_type"`
15-
OsTypes types.List `tfsdk:"os_types"`
16-
Tags types.List `tfsdk:"tags"`
17-
Meta types.String `tfsdk:"meta"`
18-
Entries types.String `tfsdk:"entries"`
19-
Comments types.List `tfsdk:"comments"`
20-
ExpireTime types.String `tfsdk:"expire_time"`
21-
CreatedAt types.String `tfsdk:"created_at"`
22-
CreatedBy types.String `tfsdk:"created_by"`
23-
UpdatedAt types.String `tfsdk:"updated_at"`
24-
UpdatedBy types.String `tfsdk:"updated_by"`
25-
TieBreakerID types.String `tfsdk:"tie_breaker_id"`
9+
ID types.String `tfsdk:"id"`
10+
ItemID types.String `tfsdk:"item_id"`
11+
ListID types.String `tfsdk:"list_id"`
12+
Name types.String `tfsdk:"name"`
13+
Description types.String `tfsdk:"description"`
14+
Type types.String `tfsdk:"type"`
15+
NamespaceType types.String `tfsdk:"namespace_type"`
16+
OsTypes types.List `tfsdk:"os_types"`
17+
Tags types.List `tfsdk:"tags"`
18+
Meta types.String `tfsdk:"meta"`
19+
Entries jsontypes.Normalized `tfsdk:"entries"`
20+
Comments types.List `tfsdk:"comments"`
21+
ExpireTime types.String `tfsdk:"expire_time"`
22+
CreatedAt types.String `tfsdk:"created_at"`
23+
CreatedBy types.String `tfsdk:"created_by"`
24+
UpdatedAt types.String `tfsdk:"updated_at"`
25+
UpdatedBy types.String `tfsdk:"updated_by"`
26+
TieBreakerID types.String `tfsdk:"tie_breaker_id"`
2627
}
2728

2829
type CommentModel struct {

internal/kibana/security/exception_item/schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
_ "embed"
66

7+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
78
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
89
"github.com/hashicorp/terraform-plugin-framework/resource"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -91,6 +92,7 @@ func (r *ExceptionItemResource) Schema(_ context.Context, _ resource.SchemaReque
9192
"entries": schema.StringAttribute{
9293
MarkdownDescription: "The exception item entries as JSON string. This defines the conditions under which the exception applies.",
9394
Required: true,
95+
CustomType: jsontypes.NormalizedType{},
9496
},
9597
"comments": schema.ListNestedAttribute{
9698
MarkdownDescription: "Array of comments about the exception item.",

internal/kibana/security/exception_list/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (r *ExceptionListResource) Update(ctx context.Context, req resource.UpdateR
3131
Id: &id,
3232
Name: kbapi.SecurityExceptionsAPIExceptionListName(plan.Name.ValueString()),
3333
Description: kbapi.SecurityExceptionsAPIExceptionListDescription(plan.Description.ValueString()),
34+
Type: kbapi.SecurityExceptionsAPIExceptionListType(plan.Type.ValueString()),
3435
}
3536

3637
// Set optional namespace_type (should not change, but include it)

0 commit comments

Comments
 (0)