Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alerting: update route schema to require group_by only for the root policy #1072

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/resources/notification_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ resource "grafana_notification_policy" "my_notification_policy" {
value = "myvalue"
}
contact_point = grafana_contact_point.a_contact_point.name
group_by = ["alertname"]
continue = true
mute_timings = [grafana_mute_timing.a_mute_timing.name]

Expand Down Expand Up @@ -112,11 +111,11 @@ resource "grafana_notification_policy" "my_notification_policy" {
Required:

- `contact_point` (String) The contact point to route notifications that match this rule to.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.

Optional:

- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping. Required for root policy only. If empty, the parent grouping is used.
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--matcher))
Expand All @@ -140,11 +139,11 @@ Required:
Required:

- `contact_point` (String) The contact point to route notifications that match this rule to.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.

Optional:

- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping. Required for root policy only. If empty, the parent grouping is used.
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--policy--matcher))
Expand All @@ -168,11 +167,11 @@ Required:
Required:

- `contact_point` (String) The contact point to route notifications that match this rule to.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.

Optional:

- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping. Required for root policy only. If empty, the parent grouping is used.
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--policy--policy--matcher))
Expand All @@ -196,7 +195,7 @@ Required:
Required:

- `contact_point` (String) The contact point to route notifications that match this rule to.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping. Required for root policy only. If empty, the parent grouping is used.

Optional:

Expand Down
1 change: 0 additions & 1 deletion examples/resources/grafana_notification_policy/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ resource "grafana_notification_policy" "my_notification_policy" {
value = "myvalue"
}
contact_point = grafana_contact_point.a_contact_point.name
group_by = ["alertname"]
continue = true
mute_timings = [grafana_mute_timing.a_mute_timing.name]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"

gapi "github.com/grafana/grafana-api-golang-client"
"github.com/grafana/terraform-provider-grafana/internal/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/grafana/terraform-provider-grafana/internal/common"
)

func ResourceNotificationPolicy() *schema.Resource {
Expand Down Expand Up @@ -96,8 +97,9 @@ func policySchema(depth uint) *schema.Resource {
},
"group_by": {
Type: schema.TypeList,
Required: true,
Description: "A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.",
Required: depth == 1,
Optional: depth > 1,
Description: "A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping. Required for root policy only. If empty, the parent grouping is used.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down