Skip to content

Commit 20b443d

Browse files
committed
Use composite id for internal id
1 parent d89ae58 commit 20b443d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

internal/kibana/security_list/models.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
9+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
910
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
1011
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1112
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -112,7 +113,13 @@ func (m *SecurityListModel) toUpdateRequest() (*kbapi.UpdateListJSONRequestBody,
112113
func (m *SecurityListModel) fromAPI(ctx context.Context, apiList *kbapi.SecurityListsAPIList) diag.Diagnostics {
113114
var diags diag.Diagnostics
114115

115-
m.ID = utils.StringishValue(apiList.Id)
116+
// Create composite ID from space_id and list_id
117+
compId := clients.CompositeId{
118+
ClusterId: m.SpaceID.ValueString(),
119+
ResourceId: string(apiList.Id),
120+
}
121+
m.ID = types.StringValue(compId.String())
122+
116123
m.ListID = utils.StringishValue(apiList.Id)
117124
m.Name = utils.StringishValue(apiList.Name)
118125
m.Description = utils.StringishValue(apiList.Description)

internal/kibana/security_list/read.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55

66
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
7+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
78
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
89
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
911
)
1012

1113
func (r *securityListResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
@@ -21,10 +23,20 @@ func (r *securityListResource) Read(ctx context.Context, req resource.ReadReques
2123
return
2224
}
2325

26+
// Parse composite ID to get space_id and list_id
2427
spaceID := state.SpaceID.ValueString()
28+
listID := state.ListID.ValueString()
29+
30+
// Try to parse as composite ID from state.ID
31+
if compId, diags := clients.CompositeIdFromStrFw(state.ID.ValueString()); !diags.HasError() {
32+
spaceID = compId.ClusterId
33+
listID = compId.ResourceId
34+
// Update space_id in state if it was parsed from composite ID
35+
state.SpaceID = types.StringValue(spaceID)
36+
}
2537

2638
params := &kbapi.ReadListParams{
27-
Id: kbapi.SecurityListsAPIListId(state.ID.ValueString()),
39+
Id: kbapi.SecurityListsAPIListId(listID),
2840
}
2941

3042
readResp, diags := kibana_oapi.GetList(ctx, client, spaceID, params)

0 commit comments

Comments
 (0)