Skip to content

Commit

Permalink
feat: Allow overriding labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mkilchhofer committed Aug 28, 2024
1 parent a963a68 commit ef2a381
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TODO
| disable\_provenance | Allow modifying the rule group from other sources than Terraform or the Grafana API. | `bool` | `false` | no |
| folder\_uid | The UID of the Grafana folder that the alerts belongs to. | `string` | n/a | yes |
| 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 |
| overrides | Overrides per Alert rule | <pre>map(object({<br> alert_threshold = optional(number)<br> exec_err_state = optional(string)<br> is_paused = optional(bool)<br> no_data_state = optional(string)<br> }))</pre> | `{}` | no |
| overrides | Overrides per Alert rule | <pre>map(object({<br> alert_threshold = optional(number)<br> exec_err_state = optional(string)<br> is_paused = optional(bool)<br> no_data_state = optional(string)<br> labels = optional(map(string))<br> }))</pre> | `{}` | no |
| prometheus\_alerts\_file\_path | Path to the Prometheus Alerting rules file | `string` | n/a | yes |

### Outputs
Expand Down
2 changes: 1 addition & 1 deletion grafana_alert.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "grafana_rule_group" "this" {
condition = "ALERTCONDITION"

annotations = {for k, v in rule.value.annotations : k => replace(v, "$value", "$values.QUERY_RESULT.Value")}
labels = rule.value.labels
labels = merge(rule.value.labels, try(var.overrides[rule.value.alert].labels, {}))

exec_err_state = try(var.overrides[rule.value.alert].exec_err_state, null)
is_paused = try(var.overrides[rule.value.alert].is_paused, null)
Expand Down
4 changes: 4 additions & 0 deletions test/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module "test_vmagent" {
overrides = {
"TooManyWriteErrors" = {
alert_threshold = 1

labels = {
mycustomlabel = "foobar"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ variable "overrides" {
exec_err_state = optional(string)
is_paused = optional(bool)
no_data_state = optional(string)
labels = optional(map(string))
}))
default = {}
}
Expand Down

0 comments on commit ef2a381

Please sign in to comment.