Skip to content

Commit 8271246

Browse files
committed
Use composite id for internal id
1 parent e414fc0 commit 8271246

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

internal/kibana/security_exception_list/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66

77
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
8+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
89
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
910
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
1011
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -129,7 +130,11 @@ func (r *ExceptionListResource) Create(ctx context.Context, req resource.CreateR
129130
func (r *ExceptionListResource) updateStateFromAPIResponse(ctx context.Context, model *ExceptionListModel, apiResp *kbapi.SecurityExceptionsAPIExceptionList) diag.Diagnostics {
130131
var diags diag.Diagnostics
131132

132-
model.ID = types.StringValue(string(apiResp.Id))
133+
compId := clients.CompositeId{
134+
ClusterId: model.SpaceID.ValueString(),
135+
ResourceId: string(apiResp.Id),
136+
}
137+
model.ID = types.StringValue(compId.String())
133138
model.ListID = types.StringValue(string(apiResp.ListId))
134139
model.Name = types.StringValue(string(apiResp.Name))
135140
model.Description = types.StringValue(string(apiResp.Description))

internal/kibana/security_exception_list/delete.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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"
910
)
@@ -23,12 +24,19 @@ func (r *ExceptionListResource) Delete(ctx context.Context, req resource.DeleteR
2324
return
2425
}
2526

26-
// Delete by ID
27-
id := kbapi.SecurityExceptionsAPIExceptionListId(state.ID.ValueString())
27+
// Parse composite ID to get space_id and resource_id
28+
compId, compIdDiags := clients.CompositeIdFromStrFw(state.ID.ValueString())
29+
resp.Diagnostics.Append(compIdDiags...)
30+
if resp.Diagnostics.HasError() {
31+
return
32+
}
33+
34+
// Delete by resource ID from composite ID
35+
id := kbapi.SecurityExceptionsAPIExceptionListId(compId.ResourceId)
2836
params := &kbapi.DeleteExceptionListParams{
2937
Id: &id,
3038
}
3139

32-
diags = kibana_oapi.DeleteExceptionList(ctx, client, state.SpaceID.ValueString(), params)
40+
diags = kibana_oapi.DeleteExceptionList(ctx, client, compId.ClusterId, params)
3341
resp.Diagnostics.Append(diags...)
3442
}

internal/kibana/security_exception_list/read.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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"
910
)
@@ -23,13 +24,20 @@ func (r *ExceptionListResource) Read(ctx context.Context, req resource.ReadReque
2324
return
2425
}
2526

26-
// Read by ID
27-
id := kbapi.SecurityExceptionsAPIExceptionListId(state.ID.ValueString())
27+
// Parse composite ID to get space_id and resource_id
28+
compId, compIdDiags := clients.CompositeIdFromStrFw(state.ID.ValueString())
29+
resp.Diagnostics.Append(compIdDiags...)
30+
if resp.Diagnostics.HasError() {
31+
return
32+
}
33+
34+
// Read by resource ID from composite ID
35+
id := kbapi.SecurityExceptionsAPIExceptionListId(compId.ResourceId)
2836
params := &kbapi.ReadExceptionListParams{
2937
Id: &id,
3038
}
3139

32-
readResp, diags := kibana_oapi.GetExceptionList(ctx, client, state.SpaceID.ValueString(), params)
40+
readResp, diags := kibana_oapi.GetExceptionList(ctx, client, compId.ClusterId, params)
3341
resp.Diagnostics.Append(diags...)
3442
if resp.Diagnostics.HasError() {
3543
return

internal/kibana/security_exception_list/update.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66

77
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
8+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
89
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
910
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
1011
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -25,8 +26,15 @@ func (r *ExceptionListResource) Update(ctx context.Context, req resource.UpdateR
2526
return
2627
}
2728

29+
// Parse composite ID to get space_id and resource_id
30+
compId, compIdDiags := clients.CompositeIdFromStrFw(plan.ID.ValueString())
31+
resp.Diagnostics.Append(compIdDiags...)
32+
if resp.Diagnostics.HasError() {
33+
return
34+
}
35+
2836
// Build the update request body
29-
id := kbapi.SecurityExceptionsAPIExceptionListId(plan.ID.ValueString())
37+
id := kbapi.SecurityExceptionsAPIExceptionListId(compId.ResourceId)
3038
body := kbapi.UpdateExceptionListJSONRequestBody{
3139
Id: &id,
3240
Name: kbapi.SecurityExceptionsAPIExceptionListName(plan.Name.ValueString()),

0 commit comments

Comments
 (0)