Skip to content

Commit

Permalink
Merge pull request #769 from imjaroiswebdev/serv-orch-toggle-doesnt-o…
Browse files Browse the repository at this point in the history
…ptin

[CSGI-2093] Patch - Service Orchestration enable status doesn't opt in
  • Loading branch information
imjaroiswebdev authored Nov 15, 2023
2 parents 7634a17 + 2b7e7b4 commit 3cdf794
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pagerduty/resource_pagerduty_event_orchestration_path_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func resourcePagerDutyEventOrchestrationPathService() *schema.Resource {
"enable_event_orchestration_for_service": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"set": {
Type: schema.TypeList,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3cdf794

Please sign in to comment.