@@ -342,6 +342,30 @@ func TestAccAlertRule_disableProvenance(t *testing.T) {
342342 })
343343}
344344
345+ func TestAccAlertRule_zeroSeconds (t * testing.T ) {
346+ testutils .CheckOSSTestsEnabled (t , ">=9.1.0" )
347+
348+ var group models.AlertRuleGroup
349+ var name = acctest .RandString (10 )
350+
351+ resource .ParallelTest (t , resource.TestCase {
352+ ProviderFactories : testutils .ProviderFactories ,
353+ CheckDestroy : alertingRuleGroupCheckExists .destroyed (& group , nil ),
354+ Steps : []resource.TestStep {
355+ {
356+ Config : testAccAlertRuleZeroSeconds (name ),
357+ Check : resource .ComposeTestCheckFunc (
358+ alertingRuleGroupCheckExists .exists ("grafana_rule_group.my_rule_group" , & group ),
359+ resource .TestCheckResourceAttr ("grafana_rule_group.my_rule_group" , "name" , name ),
360+ resource .TestCheckResourceAttr ("grafana_rule_group.my_rule_group" , "rule.#" , "1" ),
361+ resource .TestCheckResourceAttr ("grafana_rule_group.my_rule_group" , "rule.0.name" , "My Random Walk Alert" ),
362+ resource .TestCheckResourceAttr ("grafana_rule_group.my_rule_group" , "rule.0.for" , "0s" ),
363+ ),
364+ },
365+ },
366+ })
367+ }
368+
345369func testAccAlertRuleGroupInOrgConfig (name string , interval int , disableProvenance bool ) string {
346370 return fmt .Sprintf (`
347371resource "grafana_organization" "test" {
@@ -385,3 +409,44 @@ resource "grafana_rule_group" "test" {
385409}
386410` , name , interval , disableProvenance )
387411}
412+
413+ func testAccAlertRuleZeroSeconds (name string ) string {
414+ return fmt .Sprintf (`
415+ resource "grafana_folder" "rule_folder" {
416+ title = "%[1]s"
417+ }
418+
419+ resource "grafana_data_source" "testdata_datasource" {
420+ name = "%[1]s"
421+ type = "grafana-testdata-datasource"
422+ url = "http://localhost:3333"
423+ }
424+
425+ resource "grafana_rule_group" "my_rule_group" {
426+ name = "%[1]s"
427+ folder_uid = grafana_folder.rule_folder.uid
428+ interval_seconds = 60
429+ org_id = 1
430+
431+ rule {
432+ name = "My Random Walk Alert"
433+ condition = "C"
434+ for = "0s"
435+
436+ // Query the datasource.
437+ data {
438+ ref_id = "A"
439+ relative_time_range {
440+ from = 600
441+ to = 0
442+ }
443+ datasource_uid = grafana_data_source.testdata_datasource.uid
444+ model = jsonencode({
445+ intervalMs = 1000
446+ maxDataPoints = 43200
447+ refId = "A"
448+ })
449+ }
450+ }
451+ }` , name )
452+ }
0 commit comments