Skip to content

Commit 2766bd3

Browse files
authored
[Fix] Adds check to ensure that the Grafana-Terraform-Provider header is set (#1631)
* adds check to ensure the Grafana-Terraform-Provider header is set to true * lint * fix * revert changes to resource_slo.go * add error check within tests to ensure that the terraform header is set * check SLO deletion * modify pointers * lint * lint
1 parent 7809a12 commit 2766bd3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

internal/resources/slo/resource_slo.go

-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, client *slo.AP
305305

306306
req := client.DefaultAPI.V1SloIdGet(ctx, sloID)
307307
slo, _, err := req.Execute()
308-
309308
if err != nil {
310309
return apiError("Unable to read SLO - API", err)
311310
}

internal/resources/slo/resource_slo_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ func testAccSloCheckExists(rn string, slo *slo.SloV00Slo) resource.TestCheckFunc
112112
client := testutils.Provider.Meta().(*common.Client).SLOClient
113113
req := client.DefaultAPI.V1SloIdGet(context.Background(), rs.Primary.ID)
114114
gotSlo, _, err := req.Execute()
115-
116115
if err != nil {
117116
return fmt.Errorf("error getting SLO: %s", err)
118117
}
119118

119+
if *gotSlo.ReadOnly.Provenance != "terraform" {
120+
return fmt.Errorf("provenance header missing - verify within the Grafana Terraform Provider that the 'Grafana-Terraform-Provider' request header is set to 'true'")
121+
}
122+
120123
*slo = *gotSlo
121124

122125
return nil
@@ -155,6 +158,7 @@ func testAccSloCheckDestroy(slo *slo.SloV00Slo) resource.TestCheckFunc {
155158
if resp.StatusCode == 404 {
156159
return nil
157160
}
161+
158162
if gotSlo.ReadOnly.Status.Type == "deleting" {
159163
return nil
160164
}

0 commit comments

Comments
 (0)