From 786c48b55385cfaf65521cd51b9d56b2ac3c4a03 Mon Sep 17 00:00:00 2001 From: boneff Date: Mon, 27 May 2024 12:04:15 +0300 Subject: [PATCH] feat: improve PD service time window validation to accept 86400 as a valid value --- pagerduty/resource_pagerduty_service.go | 7 +++-- pagerduty/resource_pagerduty_service_test.go | 27 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 03228046e..01e6510a3 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -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 @@ -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, }) } diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go index 10e6cfcc0..f14796830 100644 --- a/pagerduty/resource_pagerduty_service_test.go +++ b/pagerduty/resource_pagerduty_service_test.go @@ -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" }