88 "net/http"
99
1010 "github.com/elastic/terraform-provider-elasticstack/internal/clients"
11+ "github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
1112 "github.com/elastic/terraform-provider-elasticstack/internal/models"
12- "github.com/elastic/terraform-provider-elasticstack/internal/utils"
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1414)
1515
@@ -24,7 +24,7 @@ func GetClusterInfo(ctx context.Context, apiClient *clients.ApiClient) (*models.
2424 return nil , diag .FromErr (err )
2525 }
2626 defer res .Body .Close ()
27- if diags := utils .CheckError (res , "Unable to connect to the Elasticsearch cluster" ); diags .HasError () {
27+ if diags := diagutil .CheckError (res , "Unable to connect to the Elasticsearch cluster" ); diags .HasError () {
2828 return nil , diags
2929 }
3030
@@ -50,7 +50,7 @@ func PutSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient, re
5050 return diag .FromErr (err )
5151 }
5252 defer res .Body .Close ()
53- if diags := utils .CheckError (res , "Unable to create or update the snapshot repository" ); diags .HasError () {
53+ if diags := diagutil .CheckError (res , "Unable to create or update the snapshot repository" ); diags .HasError () {
5454 return diags
5555 }
5656
@@ -72,7 +72,7 @@ func GetSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient, na
7272 if res .StatusCode == http .StatusNotFound {
7373 return nil , nil
7474 }
75- if diags := utils .CheckError (res , fmt .Sprintf ("Unable to get the information about snapshot repository: %s" , name )); diags .HasError () {
75+ if diags := diagutil .CheckError (res , fmt .Sprintf ("Unable to get the information about snapshot repository: %s" , name )); diags .HasError () {
7676 return nil , diags
7777 }
7878 snapRepoResponse := make (map [string ]models.SnapshotRepository )
@@ -106,7 +106,7 @@ func DeleteSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient,
106106 return diag .FromErr (err )
107107 }
108108 defer res .Body .Close ()
109- if diags := utils .CheckError (res , fmt .Sprintf ("Unable to delete snapshot repository: %s" , name )); diags .HasError () {
109+ if diags := diagutil .CheckError (res , fmt .Sprintf ("Unable to delete snapshot repository: %s" , name )); diags .HasError () {
110110 return diags
111111 }
112112 return diags
@@ -129,7 +129,7 @@ func PutSlm(ctx context.Context, apiClient *clients.ApiClient, slm *models.Snaps
129129 return diag .FromErr (err )
130130 }
131131 defer res .Body .Close ()
132- if diags := utils .CheckError (res , "Unable to create or update the SLM" ); diags .HasError () {
132+ if diags := diagutil .CheckError (res , "Unable to create or update the SLM" ); diags .HasError () {
133133 return diags
134134 }
135135
@@ -151,7 +151,7 @@ func GetSlm(ctx context.Context, apiClient *clients.ApiClient, slmName string) (
151151 if res .StatusCode == http .StatusNotFound {
152152 return nil , nil
153153 }
154- if diags := utils .CheckError (res , "Unable to get SLM policy from ES API" ); diags .HasError () {
154+ if diags := diagutil .CheckError (res , "Unable to get SLM policy from ES API" ); diags .HasError () {
155155 return nil , diags
156156 }
157157 type SlmResponse = map [string ]struct {
@@ -183,7 +183,7 @@ func DeleteSlm(ctx context.Context, apiClient *clients.ApiClient, slmName string
183183 return diag .FromErr (err )
184184 }
185185 defer res .Body .Close ()
186- if diags := utils .CheckError (res , fmt .Sprintf ("Unable to delete SLM policy: %s" , slmName )); diags .HasError () {
186+ if diags := diagutil .CheckError (res , fmt .Sprintf ("Unable to delete SLM policy: %s" , slmName )); diags .HasError () {
187187 return diags
188188 }
189189
@@ -205,7 +205,7 @@ func PutSettings(ctx context.Context, apiClient *clients.ApiClient, settings map
205205 return diag .FromErr (err )
206206 }
207207 defer res .Body .Close ()
208- if diags := utils .CheckError (res , "Unable to update cluster settings." ); diags .HasError () {
208+ if diags := diagutil .CheckError (res , "Unable to update cluster settings." ); diags .HasError () {
209209 return diags
210210 }
211211 return diags
@@ -223,7 +223,7 @@ func GetSettings(ctx context.Context, apiClient *clients.ApiClient) (map[string]
223223 return nil , diag .FromErr (err )
224224 }
225225 defer res .Body .Close ()
226- if diags := utils .CheckError (res , "Unable to read cluster settings." ); diags .HasError () {
226+ if diags := diagutil .CheckError (res , "Unable to read cluster settings." ); diags .HasError () {
227227 return nil , diags
228228 }
229229
@@ -247,7 +247,7 @@ func GetScript(ctx context.Context, apiClient *clients.ApiClient, id string) (*m
247247 if res .StatusCode == http .StatusNotFound {
248248 return nil , nil
249249 }
250- if diags := utils .CheckError (res , fmt .Sprintf ("Unable to get stored script: %s" , id )); diags .HasError () {
250+ if diags := diagutil .CheckError (res , fmt .Sprintf ("Unable to get stored script: %s" , id )); diags .HasError () {
251251 return nil , diags
252252 }
253253 var scriptResponse struct {
@@ -279,7 +279,7 @@ func PutScript(ctx context.Context, apiClient *clients.ApiClient, script *models
279279 return diag .FromErr (err )
280280 }
281281 defer res .Body .Close ()
282- if diags := utils .CheckError (res , "Unable to put stored script" ); diags .HasError () {
282+ if diags := diagutil .CheckError (res , "Unable to put stored script" ); diags .HasError () {
283283 return diags
284284 }
285285 return nil
@@ -295,7 +295,7 @@ func DeleteScript(ctx context.Context, apiClient *clients.ApiClient, id string)
295295 return diag .FromErr (err )
296296 }
297297 defer res .Body .Close ()
298- if diags := utils .CheckError (res , fmt .Sprintf ("Unable to delete script: %s" , id )); diags .HasError () {
298+ if diags := diagutil .CheckError (res , fmt .Sprintf ("Unable to delete script: %s" , id )); diags .HasError () {
299299 return diags
300300 }
301301 return nil
0 commit comments