Skip to content

Commit a7172b9

Browse files
authored
Merge pull request #1035 from PagerDuty/cjavier/allow-delete-24h-content-based
Allow deleting alert_grouping_parameters with a time_window equal to 86400
2 parents 64dee57 + eff6489 commit a7172b9

File tree

2 files changed

+103
-5
lines changed

2 files changed

+103
-5
lines changed

pagerduty/resource_pagerduty_service.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func customizePagerDutyServiceDiff(context context.Context, diff *schema.Resourc
352352
if agpType == "content_based" && (aggregateVal == "" || len(fieldsVal) == 0) {
353353
return fmt.Errorf("When using Alert grouping parameters configuration of type \"content_based\" is in use, attributes \"aggregate\" and \"fields\" are required")
354354
}
355-
if timeWindowVal == 86400 && agpType != "content_based" {
355+
if timeWindowVal == 86400 && agpType != "" && agpType != "content_based" {
356356
return fmt.Errorf("Alert grouping parameters configuration attribute \"time_window\" with a value of 86400 is only supported by \"content-based\" type Alert Grouping")
357357
}
358358
if (aggregateVal != "" || len(fieldsVal) > 0) && (agpType != "" && hasChangeAgpType && agpType != "content_based") {
@@ -590,20 +590,25 @@ func flattenService(d *schema.ResourceData, service *pagerduty.Service) error {
590590
d.Set("created_at", service.CreatedAt)
591591
d.Set("escalation_policy", service.EscalationPolicy.ID)
592592
d.Set("description", service.Description)
593+
d.Set("alert_creation", service.AlertCreation)
594+
d.Set("last_incident_timestamp", service.LastIncidentTimestamp)
595+
593596
if service.AutoResolveTimeout == nil {
594597
d.Set("auto_resolve_timeout", "null")
595598
} else {
596599
d.Set("auto_resolve_timeout", strconv.Itoa(*service.AutoResolveTimeout))
597600
}
598-
d.Set("last_incident_timestamp", service.LastIncidentTimestamp)
601+
599602
if service.AcknowledgementTimeout == nil {
600603
d.Set("acknowledgement_timeout", "null")
601604
} else {
602605
d.Set("acknowledgement_timeout", strconv.Itoa(*service.AcknowledgementTimeout))
603606
}
604-
d.Set("alert_creation", service.AlertCreation)
605-
if service.AlertGrouping != nil && *service.AlertGrouping != nil && **service.AlertGrouping != "" {
606-
d.Set("alert_grouping", **service.AlertGrouping)
607+
608+
if service.AlertGrouping != nil && *service.AlertGrouping != nil {
609+
if ag := **service.AlertGrouping; ag != "" && ag != "rules" {
610+
d.Set("alert_grouping", ag)
611+
}
607612
}
608613
if service.AlertGroupingTimeout == nil {
609614
d.Set("alert_grouping_timeout", "null")

pagerduty/resource_pagerduty_service_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,38 @@ func TestAccPagerDutyService_AlertContentGroupingIntelligentTimeWindow(t *testin
684684
})
685685
}
686686

687+
func TestAccPagerDutyService_Delete24HAlertGrouping(t *testing.T) {
688+
group := fmt.Sprintf("tf-%s", acctest.RandString(5))
689+
email := fmt.Sprintf("%[email protected]", group)
690+
service := fmt.Sprintf("tf-%s", acctest.RandString(5))
691+
692+
resource.Test(t, resource.TestCase{
693+
PreCheck: func() { testAccPreCheck(t) },
694+
Providers: testAccProviders,
695+
CheckDestroy: testAccCheckPagerDutyServiceDestroy,
696+
Steps: []resource.TestStep{
697+
{
698+
Config: testAccCheckPagerDutyServiceConfigWithAlertContentGrouping24H(group, email, group, service),
699+
Check: resource.ComposeTestCheckFunc(
700+
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
701+
resource.TestCheckResourceAttr("pagerduty_service.foo", "name", service),
702+
resource.TestCheckResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.type", "content_based"),
703+
resource.TestCheckResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.config.0.time_window", "86400"),
704+
),
705+
},
706+
{
707+
Config: testAccCheckPagerDutyServiceConfigWithAlertContentGrouping24HUpdated(group, email, group, service),
708+
Check: resource.ComposeTestCheckFunc(
709+
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
710+
resource.TestCheckResourceAttr("pagerduty_service.foo", "name", service),
711+
resource.TestCheckNoResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.type"),
712+
resource.TestCheckNoResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.config.0.time_window"),
713+
),
714+
},
715+
},
716+
})
717+
}
718+
687719
func TestAccPagerDutyService_AutoPauseNotificationsParameters(t *testing.T) {
688720
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
689721
email := fmt.Sprintf("%[email protected]", username)
@@ -1444,6 +1476,67 @@ resource "pagerduty_service" "foo" {
14441476
`, username, email, escalationPolicy, service)
14451477
}
14461478

1479+
func testAccCheckPagerDutyServiceConfigWithAlertContentGrouping24H(username, email, escalationPolicy, service string) string {
1480+
return fmt.Sprintf(`
1481+
resource "pagerduty_user" "foo" {
1482+
name = "%s"
1483+
email = "%s"
1484+
}
1485+
1486+
resource "pagerduty_escalation_policy" "foo" {
1487+
name = "%s"
1488+
num_loops = 2
1489+
rule {
1490+
escalation_delay_in_minutes = 10
1491+
target {
1492+
type = "user_reference"
1493+
id = pagerduty_user.foo.id
1494+
}
1495+
}
1496+
}
1497+
1498+
resource "pagerduty_service" "foo" {
1499+
name = "%s"
1500+
escalation_policy = pagerduty_escalation_policy.foo.id
1501+
alert_grouping_parameters {
1502+
type = "content_based"
1503+
config {
1504+
time_window = 86400
1505+
aggregate = "all"
1506+
fields = ["custom_details.field1"]
1507+
}
1508+
}
1509+
}`, username, email, escalationPolicy, service)
1510+
}
1511+
1512+
func testAccCheckPagerDutyServiceConfigWithAlertContentGrouping24HUpdated(username, email, escalationPolicy, service string) string {
1513+
return fmt.Sprintf(`
1514+
resource "pagerduty_user" "foo" {
1515+
name = "%s"
1516+
email = "%s"
1517+
}
1518+
1519+
resource "pagerduty_escalation_policy" "foo" {
1520+
name = "%s"
1521+
num_loops = 2
1522+
rule {
1523+
escalation_delay_in_minutes = 10
1524+
target {
1525+
type = "user_reference"
1526+
id = pagerduty_user.foo.id
1527+
}
1528+
}
1529+
}
1530+
1531+
resource "pagerduty_service" "foo" {
1532+
name = "%s"
1533+
escalation_policy = pagerduty_escalation_policy.foo.id
1534+
alert_grouping_parameters {
1535+
type = null
1536+
}
1537+
}`, username, email, escalationPolicy, service)
1538+
}
1539+
14471540
func testAccCheckPagerDutyServiceConfigWithAlertContentGroupingIntelligentTimeWindow(username, email, escalationPolicy, service string) string {
14481541
return fmt.Sprintf(`
14491542
resource "pagerduty_user" "foo" {

0 commit comments

Comments
 (0)