From 9f5ebfeed8e6cf053e37e1fb985eecf2095c8a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Wed, 31 Jul 2024 16:09:55 -0400 Subject: [PATCH 1/2] update flattening of auto pause notif params in service --- pagerduty/resource_pagerduty_service.go | 3 + pagerduty/resource_pagerduty_service_test.go | 140 +------------------ 2 files changed, 5 insertions(+), 138 deletions(-) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 5ab677f44..6d34057c1 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -757,6 +757,9 @@ func flattenAutoPauseNotificationsParameters(v *pagerduty.AutoPauseNotifications if v.Enabled { autoPauseNotificationsParameters["timeout"] = v.Timeout } + if !v.Enabled && v.Timeout == nil { + autoPauseNotificationsParameters["timeout"] = 120 + } return []interface{}{autoPauseNotificationsParameters} } diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go index 1a73b0f47..96ccb4aad 100644 --- a/pagerduty/resource_pagerduty_service_test.go +++ b/pagerduty/resource_pagerduty_service_test.go @@ -402,70 +402,8 @@ func TestAccPagerDutyService_FormatValidation(t *testing.T) { } func TestAccPagerDutyService_AlertGrouping(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)) - service := fmt.Sprintf("tf-%s", acctest.RandString(5)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccPreCheckPagerDutyAbility(t, "preview_intelligent_alert_grouping") }, - Providers: testAccProviders, - CheckDestroy: testAccCheckPagerDutyServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckPagerDutyServiceConfigWithAlertGrouping(username, email, escalationPolicy, service), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", service), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "description", "foo"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "auto_resolve_timeout", "1800"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "acknowledgement_timeout", "1800"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_creation", "create_alerts_and_incidents"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_grouping", "time"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_grouping_timeout", "1800"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.#", "1"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.0.urgency", "high"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), - ), - }, - { - Config: testAccCheckPagerDutyServiceConfigWithAlertGroupingUpdated(username, email, escalationPolicy, service), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyServiceExists("pagerduty_service.foo"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "name", service), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "description", "foo"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "auto_resolve_timeout", "1800"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "acknowledgement_timeout", "1800"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_creation", "create_alerts_and_incidents"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_grouping", "intelligent"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "alert_grouping_timeout", "1900"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.#", "1"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.0.urgency", "high"), - resource.TestCheckResourceAttr( - "pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), - ), - }, - }, - }) + // Attributes alert_grouping and alert_grouping_timeout are deprecated + // and will be removed in a future release. } func TestAccPagerDutyService_AlertContentGrouping(t *testing.T) { @@ -1464,43 +1402,6 @@ resource "pagerduty_service" "foo" { `, username, email, escalationPolicy, service, customAdditionalServiceConfig) } -func testAccCheckPagerDutyServiceConfigWithAlertGrouping(username, email, escalationPolicy, service string) string { - return fmt.Sprintf(` -resource "pagerduty_user" "foo" { - name = "%s" - email = "%s" - color = "green" - role = "user" - job_title = "foo" - description = "foo" -} - -resource "pagerduty_escalation_policy" "foo" { - name = "%s" - description = "bar" - num_loops = 2 - rule { - escalation_delay_in_minutes = 10 - target { - type = "user_reference" - id = pagerduty_user.foo.id - } - } -} - -resource "pagerduty_service" "foo" { - name = "%s" - description = "foo" - auto_resolve_timeout = 1800 - acknowledgement_timeout = 1800 - escalation_policy = pagerduty_escalation_policy.foo.id - alert_creation = "create_alerts_and_incidents" - alert_grouping = "time" - alert_grouping_timeout = 1800 -} -`, username, email, escalationPolicy, service) -} - func testAccCheckPagerDutyServiceConfigWithAlertContentGrouping(username, email, escalationPolicy, service string) string { return fmt.Sprintf(` resource "pagerduty_user" "foo" { @@ -1741,43 +1642,6 @@ resource "pagerduty_service" "foo" { `, username, email, escalationPolicy, service) } -func testAccCheckPagerDutyServiceConfigWithAlertGroupingUpdated(username, email, escalationPolicy, service string) string { - return fmt.Sprintf(` -resource "pagerduty_user" "foo" { - name = "%s" - email = "%s" - color = "green" - role = "user" - job_title = "foo" - description = "foo" -} - -resource "pagerduty_escalation_policy" "foo" { - name = "%s" - description = "bar" - num_loops = 2 - rule { - escalation_delay_in_minutes = 10 - target { - type = "user_reference" - id = pagerduty_user.foo.id - } - } -} - -resource "pagerduty_service" "foo" { - name = "%s" - description = "foo" - auto_resolve_timeout = 1800 - acknowledgement_timeout = 1800 - escalation_policy = pagerduty_escalation_policy.foo.id - alert_creation = "create_alerts_and_incidents" - alert_grouping = "intelligent" - alert_grouping_timeout = 1900 -} -`, username, email, escalationPolicy, service) -} - func testAccCheckPagerDutyServiceConfigWithAlertIntelligentGroupingUpdated(username, email, escalationPolicy, service string) string { return fmt.Sprintf(` resource "pagerduty_user" "foo" { From 5bd5ece004e0d30ba87ed1f7c11b3ab18c24f44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Wed, 31 Jul 2024 16:20:03 -0400 Subject: [PATCH 2/2] add test cases for service import --- pagerduty/import_pagerduty_service_test.go | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pagerduty/import_pagerduty_service_test.go b/pagerduty/import_pagerduty_service_test.go index bb64798ea..e59d35c7c 100644 --- a/pagerduty/import_pagerduty_service_test.go +++ b/pagerduty/import_pagerduty_service_test.go @@ -119,3 +119,35 @@ func TestAccPagerDutyServiceWithAutoPauseNotifications_import(t *testing.T) { }, }) } + +func TestAccPagerDutyServiceWithAutoPauseNotificationsDisabled_import(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)) + service := fmt.Sprintf("tf-%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckPagerDutyServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckPagerDutyServiceConfigWithAutoPauseNotificationsParametersUpdated(username, email, escalationPolicy, service), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "pagerduty_service.foo", "auto_pause_notifications_parameters.#", "1"), + resource.TestCheckResourceAttr( + "pagerduty_service.foo", "auto_pause_notifications_parameters.0.enabled", "false"), + resource.TestCheckResourceAttr( + "pagerduty_service.foo", "auto_pause_notifications_parameters.0.timeout", "120"), + ), + }, + + { + ResourceName: "pagerduty_service.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +}