From baa8d2619fc80e5c33ee378dd30ffc9b2a6fe546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Mon, 13 Nov 2023 15:14:24 -0300 Subject: [PATCH 1/2] update logic for enabling serv status activation --- ...erduty_event_orchestration_path_service.go | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_service.go b/pagerduty/resource_pagerduty_event_orchestration_path_service.go index 8c934ca23..53c56f2ea 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_service.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_service.go @@ -107,6 +107,7 @@ func resourcePagerDutyEventOrchestrationPathService() *schema.Resource { "enable_event_orchestration_for_service": { Type: schema.TypeBool, Optional: true, + Computed: true, }, "set": { Type: schema.TypeList, @@ -318,14 +319,22 @@ func resourcePagerDutyEventOrchestrationPathServiceUpdate(ctx context.Context, d func needToUpdateServiceActiveStatus(d *schema.ResourceData) bool { var needToUpdate bool - if d.HasChange("enable_event_orchestration_for_service") { - o, n := d.GetChange("enable_event_orchestration_for_service") - old := o.(bool) - new := n.(bool) - _, ok := d.GetOkExists("enable_event_orchestration_for_service") - if ok || old != new && new == false { - needToUpdate = true - } + o, n := d.GetChange("enable_event_orchestration_for_service") + hasChanged := o != n + attrVal, isAttrSet := d.GetOkExists("enable_event_orchestration_for_service") + isNewResource := d.IsNewResource() + + isNewResAndAttrIsOmitted := !isAttrSet && !attrVal.(bool) && isNewResource + isNewResAndAttrIsSetToFalse := isAttrSet && !attrVal.(bool) && isNewResource + isNewResAndAttrIsSetToTrue := isAttrSet && attrVal.(bool) && isNewResource + isNotNewResAndAttrHasChange := hasChanged && !isNewResource + + if isNewResAndAttrIsOmitted { + return false + } + + if isNewResAndAttrIsSetToFalse || isNewResAndAttrIsSetToTrue || isNotNewResAndAttrHasChange { + needToUpdate = true } return needToUpdate From 2b7e7b4ff0b11c61872895f47e69ffeab6023dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Reyes?= Date: Mon, 13 Nov 2023 15:14:45 -0300 Subject: [PATCH 2/2] add test cases to cover regression --- ...uty_event_orchestration_path_service_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go b/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go index 4883e79dc..f342904b5 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go @@ -205,6 +205,23 @@ func TestAccPagerDutyEventOrchestrationPathService_Basic(t *testing.T) { )..., ), }, + { + Config: testAccCheckPagerDutyEventOrchestrationPathServiceResourceDeleteConfig(escalationPolicy, service), + Check: resource.ComposeTestCheckFunc( + testAccCheckPagerDutyEventOrchestrationServicePathNotExists(resourceName), + ), + }, + // Disabling Service Orchestration at creation by setting + // `enable_event_orchestration_for_service` attribute to false + { + Config: testAccCheckPagerDutyEventOrchestrationPathServiceEnableEOForServiceDisableUpdateConfig(escalationPolicy, service), + Check: resource.ComposeTestCheckFunc( + append( + baseChecks, + resource.TestCheckResourceAttr(resourceName, "enable_event_orchestration_for_service", "false"), + )..., + ), + }, { Config: testAccCheckPagerDutyEventOrchestrationPathServiceDefaultConfig(escalationPolicy, service), Check: resource.ComposeTestCheckFunc(