Skip to content

Commit 126a846

Browse files
authored
feat: Allow overriding "for" field (#8)
1 parent 5bcd3f0 commit 126a846

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Every alert supports the following overrides:
7575
| `no_data_state` | `string` | Describes what state to enter when the rule's query returns No Data. Options are `OK`, `NoData`, `KeepLast`, and `Alerting`. Defaults to `OK`. |
7676
| `annotations` | `map(string)` | Extra annotations to add. It is also possible to override already defined annotations like `runbook_url`. |
7777
| `labels` | `map(string)` | Extra labels to add. It is also possible to override already defined labels like `severity`. |
78+
| `for` | `string` | The amount of time for which the rule must be breached for the rule to be considered to be *Firing*. Before this time has elapsed, the rule is only considered to be *Pending*. Defaults to `0`. |
7879

7980

8081
## TF module documentation
@@ -95,7 +96,7 @@ Every alert supports the following overrides:
9596
| disable\_provenance | Allow modifying the rule group from other sources than Terraform or the Grafana API. | `bool` | `false` | no |
9697
| folder\_uid | The UID of the Grafana folder that the alerts belongs to. | `string` | n/a | yes |
9798
| org\_id | The Organization ID of of the Grafana Alerting rule groups. (Only supported with basic auth, API keys are already org-scoped) | `string` | `null` | no |
98-
| overrides | Overrides per Alert rule | <pre>map(object({<br> alert_threshold = optional(number)<br> exec_err_state = optional(string)<br> expr = optional(string)<br> is_paused = optional(bool)<br> no_data_state = optional(string)<br> labels = optional(map(string))<br> annotations = optional(map(string))<br> }))</pre> | `{}` | no |
99+
| overrides | Overrides per Alert rule | <pre>map(object({<br> alert_threshold = optional(number)<br> exec_err_state = optional(string)<br> expr = optional(string)<br> is_paused = optional(bool)<br> no_data_state = optional(string)<br> labels = optional(map(string))<br> annotations = optional(map(string))<br> for = optional(string)<br> }))</pre> | `{}` | no |
99100
| prometheus\_alerts\_file\_path | Path to the Prometheus Alerting rules file | `string` | n/a | yes |
100101

101102
### Outputs

grafana_alert.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "grafana_rule_group" "this" {
2020

2121
content {
2222
name = rule.value.alert
23-
for = try(rule.value.for, null)
23+
for = try(var.overrides[rule.value.alert].for, rule.value.for, null)
2424
condition = "ALERTCONDITION"
2525

2626
annotations = {

test/test.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@ module "test_vmagent" {
5656
mycustomlabel = "foobar"
5757
}
5858
}
59+
60+
"TooManyScrapeErrors" = {
61+
"for" = "20m"
62+
}
5963
}
6064
}

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ variable "overrides" {
2323
no_data_state = optional(string)
2424
labels = optional(map(string))
2525
annotations = optional(map(string))
26+
for = optional(string)
2627
}))
2728
default = {}
2829
}

0 commit comments

Comments
 (0)