Skip to content

Commit 96f5843

Browse files
committed
use custom validation
1 parent 6d0c920 commit 96f5843

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

docs/resources/rule_group.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Optional:
144144
- `is_paused` (Boolean) Sets whether the alert should be paused or not. Defaults to `false`.
145145
- `keep_firing_for` (String) The amount of time for which the rule will considered to be Recovering after initially Firing. Before this time has elapsed, the rule will continue to fire once it's been triggered.
146146
- `labels` (Map of String) Key-value pairs to attach to the alert rule that can be used in matching, grouping, and routing. Defaults to `map[]`.
147-
- `missing_series_evals_to_resolve` (Number) The number of missing series evaluations that must occur before the rule is considered to be resolved. Defaults to 2 if not set.
147+
- `missing_series_evals_to_resolve` (Number) The number of missing series evaluations that must occur before the rule is considered to be resolved.
148148
- `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 NoData if not set.
149149
- `notification_settings` (Block List, Max: 1) Notification settings for the rule. If specified, it overrides the notification policies. Available since Grafana 10.4, requires feature flag 'alertingSimplifiedRouting' to be enabled. (see [below for nested schema](#nestedblock--rule--notification_settings))
150150
- `record` (Block List, Max: 1) Settings for a recording rule. Available since Grafana 11.2, requires feature flag 'grafanaManagedRecordingRules' to be enabled. (see [below for nested schema](#nestedblock--rule--record))

internal/resources/grafana/resource_alerting_rule_group.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
goapi "github.com/grafana/grafana-openapi-client-go/client"
1616
"github.com/grafana/grafana-openapi-client-go/client/provisioning"
1717
"github.com/grafana/grafana-openapi-client-go/models"
18+
"github.com/hashicorp/go-cty/cty"
1819
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1920
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2021
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -116,10 +117,15 @@ This resource requires Grafana 9.1.0 or later.
116117
},
117118
},
118119
"missing_series_evals_to_resolve": {
119-
Type: schema.TypeInt,
120-
Optional: true,
121-
Description: "The number of missing series evaluations that must occur before the rule is considered to be resolved. Defaults to 2 if not set.",
122-
ValidateFunc: validation.IntAtLeast(1),
120+
Type: schema.TypeInt,
121+
Optional: true,
122+
Description: "The number of missing series evaluations that must occur before the rule is considered to be resolved.",
123+
ValidateDiagFunc: func(i any, path cty.Path) (diags diag.Diagnostics) {
124+
if i != nil && i.(int) < 1 {
125+
return diag.Errorf("missing_series_evals_to_resolve must be greater than or equal to 1")
126+
}
127+
return nil
128+
},
123129
},
124130
"no_data_state": {
125131
Type: schema.TypeString,

0 commit comments

Comments
 (0)