Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Schedule can't be deleted when used by EP with one layer configured #693

Conversation

imjaroiswebdev
Copy link
Contributor

This update is meant to solve two issues:

Issue 1

When there is a configuration that includes a pagerduty_schedule being used by an pagerduty_escalation_policy in its only one configured layer and happen that the Schedule is try to be destroyed, Terraform will return the following error...

╷
│ Error: DELETE API call to https://api.pagerduty.com/schedules/PSAZ43T failed 400 Bad Request. Code: 2001, Errors: [Schedule can't be deleted if it's being used by escalation policies], Message: Invalid Input Provided
│

Regardless of whether you are updating the reference to the Schedule this error will be blocking the deletion, because of the order in which the update and deletion operations are sorted by Terraform based on the dependency between the Schedule and EP.

Issue 2

When there is a configuration that includes a pagerduty_schedule being used by an pagerduty_escalation_policy with multiple layers but the same Schedule is the only configured target on each layer and happen that the Schedule is try to be destroyed, The Provider will panic with the following error...

pagerduty_schedule.foo: Destroying... [id=PZQ6J9Y]
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-pagerduty_v2.14.5 plugin:

panic: runtime error: slice bounds out of range [2:1]

goroutine 48 [running]:
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.removeScheduleFromEP(0x1400021b7c0, {0x14000119dc6, 0x7}, 0x14000441110)
        github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_schedule.go:724 +0x55c
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.dissociateScheduleFromEPs(0x1400021b7c0, {0x14000119dc6, 0x7}, {0x1400031ab40, 0x1, 0x1})
        github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_schedule.go:699 +0x270
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.resourcePagerDutyScheduleDelete.func2()
        github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_schedule.go:442 +0x308
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.RetryContext.func1()
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/resource/wait.go:27 +0x50
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext.func1(0x14000174240, 0x14000150000, 0x140004b47e0, 0x140004764c0, 0x1400043cf30, 0x1400043cf28)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/resource/state.go:110 +0x178
created by github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/resource/state.go:83 +0x174

Error: The terraform-provider-pagerduty_v2.14.5 plugin crashed!

Test cases introduced...

$ PAGERDUTY_ACC_SCHEDULE_USED_BY_EP_W_1_LAYER=1 make testacc TESTARGS="-count=1 -run TestAccPagerDutySchedule"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -count=1 -run TestAccPagerDutySchedule -timeout 120m
?       github.com/terraform-providers/terraform-provider-pagerduty     [no test files]
=== RUN   TestAccPagerDutySchedule_import
--- PASS: TestAccPagerDutySchedule_import (11.88s)
=== RUN   TestAccPagerDutySchedule_Basic
--- PASS: TestAccPagerDutySchedule_Basic (20.73s)
=== RUN   TestAccPagerDutyScheduleWithTeams_Basic
--- PASS: TestAccPagerDutyScheduleWithTeams_Basic (15.59s)
=== RUN   TestAccPagerDutySchedule_BasicWithExternalDestroyHandling
--- PASS: TestAccPagerDutySchedule_BasicWithExternalDestroyHandling (12.15s)
=== RUN   TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependant
--- PASS: TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependant (18.97s)
=== RUN   TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependantWithOneLayer # 👈 New test case
--- PASS: TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependantWithOneLayer (47.52s)
=== RUN   TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependantWithOpenIncidents
--- PASS: TestAccPagerDutyScheduleWithTeams_EscalationPolicyDependantWithOpenIncidents (50.88s)
=== RUN   TestAccPagerDutySchedule_EscalationPolicyDependantWithOpenIncidents
--- PASS: TestAccPagerDutySchedule_EscalationPolicyDependantWithOpenIncidents (52.23s)
=== RUN   TestAccPagerDutyScheduleOverflow_Basic
--- PASS: TestAccPagerDutyScheduleOverflow_Basic (14.24s)
=== RUN   TestAccPagerDutySchedule_BasicWeek
--- PASS: TestAccPagerDutySchedule_BasicWeek (14.24s)
=== RUN   TestAccPagerDutySchedule_Multi
--- PASS: TestAccPagerDutySchedule_Multi (15.36s)
PASS
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   274.275s

@imjaroiswebdev imjaroiswebdev force-pushed the error-del-schedule-used-by-ep-w-1-layer branch from a78acf5 to 32e6944 Compare May 29, 2023 22:35
@imjaroiswebdev imjaroiswebdev merged commit cd84d92 into PagerDuty:master May 29, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant