Skip to content

Commit 10cd43e

Browse files
committed
Patch delete agent policy spec
1 parent 0359a86 commit 10cd43e

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

generated/kbapi/kibana.gen.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/kbapi/transform_schema.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,18 @@ func transformKibanaPaths(schema *Schema) {
820820

821821
schema.Components.CreateRef(schema, "Data_views_create_data_view_request_object_inner", "schemas.Data_views_create_data_view_request_object.properties.data_view")
822822
schema.Components.CreateRef(schema, "Data_views_update_data_view_request_object_inner", "schemas.Data_views_update_data_view_request_object.properties.data_view")
823+
824+
// Can be removed when https://github.com/elastic/kibana/pull/226713 is merged
825+
schema.Components.Set("schemas.APM_UI_delete_service_object", Map{
826+
"type": "object",
827+
"properties": Map{
828+
"service": Map{
829+
"$ref": "#/components/schemas/APM_UI_service_object",
830+
},
831+
},
832+
})
833+
agentConfigPath := schema.MustGetPath("/api/apm/settings/agent-configuration")
834+
agentConfigPath.Delete.Set("requestBody.content.application/json.schema.$ref", "#/components/schemas/APM_UI_delete_service_object")
823835
}
824836

825837
// transformFleetPaths fixes the fleet paths.

internal/apm/agent_configuration/delete.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package agent_configuration
22

33
import (
4-
"bytes"
54
"context"
6-
"encoding/json"
75
"fmt"
86
"strings"
97

@@ -13,13 +11,6 @@ import (
1311
"github.com/hashicorp/terraform-plugin-log/tflog"
1412
)
1513

16-
type deleteAgentConfigurationRequestBody struct {
17-
Service struct {
18-
Name string `json:"name"`
19-
Environment *string `json:"environment,omitempty"`
20-
} `json:"service"`
21-
}
22-
2314
func (r *resourceAgentConfiguration) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
2415
var state AgentConfiguration
2516
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
@@ -40,17 +31,13 @@ func (r *resourceAgentConfiguration) Delete(ctx context.Context, req resource.De
4031
serviceEnv = &idParts[1]
4132
}
4233

43-
deleteReqBody := deleteAgentConfigurationRequestBody{}
44-
deleteReqBody.Service.Name = serviceName
45-
deleteReqBody.Service.Environment = serviceEnv
46-
47-
bodyBytes, err := json.Marshal(deleteReqBody)
48-
if err != nil {
49-
resp.Diagnostics.AddError("Failed to serialize delete request body", err.Error())
50-
return
34+
deleteReqBody := kbapi.APMUIDeleteServiceObject{
35+
Service: &kbapi.APMUIServiceObject{
36+
Name: &serviceName,
37+
Environment: serviceEnv,
38+
},
5139
}
52-
53-
apiResp, err := kibana.API.DeleteAgentConfigurationWithBody(ctx, &kbapi.DeleteAgentConfigurationParams{}, "application/json", bytes.NewReader(bodyBytes))
40+
apiResp, err := kibana.API.DeleteAgentConfiguration(ctx, &kbapi.DeleteAgentConfigurationParams{}, deleteReqBody)
5441
if err != nil {
5542
resp.Diagnostics.AddError("Failed to delete APM agent configuration", err.Error())
5643
return

0 commit comments

Comments
 (0)