Skip to content

Commit

Permalink
feat: improve PD service time window validation to accept 86400 as a …
Browse files Browse the repository at this point in the history
…valid value
  • Loading branch information
boneff committed May 27, 2024
1 parent de61b16 commit 786c48b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func customizePagerDutyServiceDiff(context context.Context, diff *schema.Resourc
if (timeWindowVal > 300) && (agpType != "" && hasChangeAgpType && (agpType != "intelligent" && agpType != "content_based")) {
return fmt.Errorf("Alert grouping parameters configuration attribute \"time_window\" is only supported by \"intelligent\" and \"content-based\" type Alert Grouping")
}
if timeWindowVal == 86400 && agpType != "content_based" {
return fmt.Errorf("Alert grouping parameters configuration attribute \"time_window\" with a value of 86400 is only supported by \"content-based\" type Alert Grouping")
}
}

return nil
Expand All @@ -369,10 +372,10 @@ func validateTimeWindow(v interface{}, p cty.Path) diag.Diagnostics {
var diags diag.Diagnostics

tw := v.(int)
if tw < 300 || tw > 3600 {
if (tw < 300 || tw > 3600) && tw != 86400 {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("Alert grouping time window value must be between 300 and 3600, current setting is %d", tw),
Summary: fmt.Sprintf("Alert grouping time window value must be between 300 and 3600 or exactly 86400(86400 is supported only for content-based alert grouping), current setting is %d", tw),
AttributePath: p,
})
}
Expand Down
27 changes: 27 additions & 0 deletions pagerduty/resource_pagerduty_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,33 @@ func TestAccPagerDutyService_FormatValidation(t *testing.T) {
{
Config: testAccCheckPagerDutyServiceCustomInputValidationConfig(username, email, escalationPolicy, service,
`
alert_grouping_parameters {
type = "content_based"
config {
time_window = 86400
}
}
`,
),
PlanOnly: true,
},
{
Config: testAccCheckPagerDutyServiceCustomInputValidationConfig(username, email, escalationPolicy, service,
`
alert_grouping_parameters {
type = "intelligent"
config {
time_window = 86400
}
}
`,
),
PlanOnly: true,
ExpectError: regexp.MustCompile("Alert grouping parameters configuration attribute \"time_window\" with a value of 86400 is only supported by \"content-based\" type Alert Grouping"),
},
{
Config: testAccCheckPagerDutyServiceCustomInputValidationConfig(username, email, escalationPolicy, service,
`
alert_grouping_parameters {
type = "intelligent"
}
Expand Down

0 comments on commit 786c48b

Please sign in to comment.