@@ -20,7 +20,7 @@ const (
2020 QueryTypeThreshold string = "threshold"
2121)
2222
23- func ResourceSlo () * schema.Resource {
23+ func resourceSlo () * schema.Resource {
2424 return & schema.Resource {
2525 Description : `
2626Resource manages Grafana SLOs.
@@ -29,10 +29,10 @@ Resource manages Grafana SLOs.
2929* [API documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/api/)
3030* [Additional Information On Alerting Rule Annotations and Labels](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/)
3131 ` ,
32- CreateContext : resourceSloCreate ,
33- ReadContext : resourceSloRead ,
34- UpdateContext : resourceSloUpdate ,
35- DeleteContext : resourceSloDelete ,
32+ CreateContext : withClient [schema. CreateContextFunc ]( resourceSloCreate ) ,
33+ ReadContext : withClient [schema. ReadContextFunc ]( resourceSloRead ) ,
34+ UpdateContext : withClient [schema. UpdateContextFunc ]( resourceSloUpdate ) ,
35+ DeleteContext : withClient [schema. DeleteContextFunc ]( resourceSloDelete ) ,
3636 Importer : & schema.ResourceImporter {
3737 StateContext : schema .ImportStatePassthroughContext ,
3838 },
@@ -234,7 +234,7 @@ var keyvalueSchema = &schema.Resource{
234234 },
235235}
236236
237- func resourceSloCreate (ctx context.Context , d * schema.ResourceData , m interface {} ) diag.Diagnostics {
237+ func resourceSloCreate (ctx context.Context , d * schema.ResourceData , client * slo. APIClient ) diag.Diagnostics {
238238 var diags diag.Diagnostics
239239
240240 sloModel , err := packSloResource (d )
@@ -247,7 +247,6 @@ func resourceSloCreate(ctx context.Context, d *schema.ResourceData, m interface{
247247 return diags
248248 }
249249
250- client := m .(* common.Client ).SLOClient
251250 req := client .DefaultAPI .V1SloPost (ctx ).Slo (sloModel )
252251 response , _ , err := req .Execute ()
253252
@@ -256,18 +255,16 @@ func resourceSloCreate(ctx context.Context, d *schema.ResourceData, m interface{
256255 }
257256
258257 d .SetId (response .Uuid )
259- resourceSloRead (ctx , d , m )
260258
261- return resourceSloRead (ctx , d , m )
259+ return resourceSloRead (ctx , d , client )
262260}
263261
264262// resourceSloRead - sends a GET Request to the single SLO Endpoint
265- func resourceSloRead (ctx context.Context , d * schema.ResourceData , m interface {} ) diag.Diagnostics {
263+ func resourceSloRead (ctx context.Context , d * schema.ResourceData , client * slo. APIClient ) diag.Diagnostics {
266264 var diags diag.Diagnostics
267265
268266 sloID := d .Id ()
269267
270- client := m .(* common.Client ).SLOClient
271268 req := client .DefaultAPI .V1SloIdGet (ctx , sloID )
272269 slo , _ , err := req .Execute ()
273270
@@ -280,7 +277,7 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, m interface{})
280277 return diags
281278}
282279
283- func resourceSloUpdate (ctx context.Context , d * schema.ResourceData , m interface {} ) diag.Diagnostics {
280+ func resourceSloUpdate (ctx context.Context , d * schema.ResourceData , client * slo. APIClient ) diag.Diagnostics {
284281 var diags diag.Diagnostics
285282 sloID := d .Id ()
286283
@@ -295,21 +292,18 @@ func resourceSloUpdate(ctx context.Context, d *schema.ResourceData, m interface{
295292 return diags
296293 }
297294
298- client := m .(* common.Client ).SLOClient
299-
300295 req := client .DefaultAPI .V1SloIdPut (ctx , sloID ).Slo (slo )
301296 if _ , err := req .Execute (); err != nil {
302297 return apiError ("Unable to Update SLO - API" , err )
303298 }
304299 }
305300
306- return resourceSloRead (ctx , d , m )
301+ return resourceSloRead (ctx , d , client )
307302}
308303
309- func resourceSloDelete (ctx context.Context , d * schema.ResourceData , m interface {} ) diag.Diagnostics {
304+ func resourceSloDelete (ctx context.Context , d * schema.ResourceData , client * slo. APIClient ) diag.Diagnostics {
310305 sloID := d .Id ()
311306
312- client := m .(* common.Client ).SLOClient
313307 req := client .DefaultAPI .V1SloIdDelete (ctx , sloID )
314308 _ , err := req .Execute ()
315309
0 commit comments