11package  agent_configuration
22
33import  (
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- 
2314func  (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