From e4a4daa0a031613294d889615d6b3856cb0a5230 Mon Sep 17 00:00:00 2001 From: Carlos Gajardo Date: Mon, 23 Dec 2024 15:29:17 -0300 Subject: [PATCH] Fix service update conflict on alert grouping rules --- pagerduty/resource_pagerduty_service.go | 8 +++++++- pagerduty/resource_pagerduty_service_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 515022fd3..1c3f35ad2 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -418,7 +418,9 @@ func buildServiceStruct(d *schema.ResourceData) (*pagerduty.Service, error) { if attr, ok := d.GetOk("alert_grouping"); ok { ag := attr.(string) - service.AlertGrouping = &ag + if ag != "rules" { + service.AlertGrouping = &ag + } } if attr, ok := d.GetOk("alert_grouping_parameters"); ok { @@ -525,6 +527,10 @@ func resourcePagerDutyServiceCreate(d *schema.ResourceData, meta interface{}) er d.SetId(service.ID) + // We wait for internal subsystem to sync. Otherwise fields like + // alert_grouping_parameters will return empty. + time.Sleep(500 * time.Millisecond) + return fetchService(d, meta, genError) } diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go index 96ccb4aad..44d102925 100644 --- a/pagerduty/resource_pagerduty_service_test.go +++ b/pagerduty/resource_pagerduty_service_test.go @@ -406,7 +406,7 @@ func TestAccPagerDutyService_AlertGrouping(t *testing.T) { // and will be removed in a future release. } -func TestAccPagerDutyService_AlertContentGrouping(t *testing.T) { +func TestAccPagerDutyService_AlertGroupingContentBased(t *testing.T) { username := fmt.Sprintf("tf-%s", acctest.RandString(5)) email := fmt.Sprintf("%s@foo.test", username) escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5))