-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerting: Remove mute timings from alert rules on deletion (#1724)
Closes #1713 This was broken in Grafana Cloud when grafana/grafana#90500 was released
- Loading branch information
1 parent
08a1309
commit 26b4ddb
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"testing" | ||
|
||
"github.com/grafana/grafana-openapi-client-go/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/grafana/terraform-provider-grafana/v3/internal/testutils" | ||
|
@@ -143,7 +144,7 @@ func TestAccMuteTiming_RemoveInUse(t *testing.T) { | |
contact_point = grafana_contact_point.default_policy.name | ||
} | ||
} | ||
resource "grafana_mute_timing" "test" { | ||
count = local.use_mute ? 1 : 0 | ||
org_id = grafana_organization.my_org.id | ||
|
@@ -164,3 +165,77 @@ func TestAccMuteTiming_RemoveInUse(t *testing.T) { | |
}, | ||
}) | ||
} | ||
|
||
func TestAccMuteTiming_RemoveInUseInAlertRule(t *testing.T) { | ||
testutils.CheckCloudInstanceTestsEnabled(t) // TODO: Switch to OSS when this is released: https://github.com/grafana/grafana/pull/90500 | ||
|
||
randomStr := acctest.RandString(6) | ||
|
||
config := func(mute bool) string { | ||
return fmt.Sprintf(` | ||
locals { | ||
use_mute = %[2]t | ||
} | ||
resource "grafana_folder" "rule_folder" { | ||
title = "%[1]s" | ||
} | ||
resource "grafana_contact_point" "default_policy" { | ||
name = "%[1]s" | ||
email { | ||
addresses = ["[email protected]"] | ||
} | ||
} | ||
resource "grafana_rule_group" "this" { | ||
name = "%[1]s" | ||
folder_uid = grafana_folder.rule_folder.uid | ||
interval_seconds = 60 | ||
rule { | ||
name = "%[1]s" | ||
condition = "B" | ||
notification_settings { | ||
contact_point = grafana_contact_point.default_policy.name | ||
group_by = ["..."] | ||
mute_timings = local.use_mute ? [grafana_mute_timing.test[0].name] : [] | ||
} | ||
data { | ||
ref_id = "A" | ||
query_type = "" | ||
relative_time_range { | ||
from = 600 | ||
to = 0 | ||
} | ||
datasource_uid = "PD8C576611E62080A" | ||
model = jsonencode({ | ||
hide = false | ||
intervalMs = 1000 | ||
maxDataPoints = 43200 | ||
refId = "A" | ||
}) | ||
} | ||
} | ||
} | ||
resource "grafana_mute_timing" "test" { | ||
count = local.use_mute ? 1 : 0 | ||
name = "%[1]s" | ||
intervals {} | ||
}`, randomStr, mute) | ||
} | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config(true), | ||
}, | ||
{ | ||
Config: config(false), | ||
}, | ||
}, | ||
}) | ||
} |