terraform-provider-pagerduty
terraform-provider-pagerduty copied to clipboard
Module doesn't understand the dependency between schedules and escalation policies
Hi there,
Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.
Terraform Version
Terraform v0.12.26
- provider.pagerduty v1.9.6
Affected Resource(s)
Please list the resources as a list, for example:
- pagerduty_schedule
- pagerduty_escalation_policy
Terraform Configuration Files
resource "pagerduty_schedule" "example" {
name = "Daily Engineering Rotation"
...
}
resource "pagerduty_escalation_policy" "example" {
name = "Engineering Escalation Policy"
teams = [pagerduty_team.example.id]
rule {
escalation_delay_in_minutes = 10
target {
type = "schedule_reference"
id = pagerduty_schedule.example.id
}
}
}
Scenario
The above pagerduty_schedule
and pagerduty_escalation_policy
exist in Pagerduty and TF state. I remove the code for the escalation policy and the schedule and run tf apply
.
Expected Behavior
I expect the pagerduty module to understand the dependency between the schedule and the escalation policy and to delete the escalation policy first and the ~policy~ schedule second.
Actual Behavior
Error: DELETE API call to https://api.pagerduty.com/schedules/TRFY575 failed 400 Bad Request. Code: 2001, Errors: [Schedule can't be deleted if it's being used by escalation policies], Message: Invalid Input Provided
Error: DELETE API call to https://api.pagerduty.com/schedules/TR2IAZ9 failed 400 Bad Request. Code: 2001, Errors: [Schedule can't be deleted if it's being used by escalation policies], Message: Invalid Input Provided
Steps to Reproduce
- Create a schedule linked to an escalation policy.
- Try delete both at the same time with
tf apply
I expect the pagerduty module to understand the dependency between the schedule and the escalation policy and to delete the escalation policy first and the policy second.
@noqcks -- I think you mean "escalation policy first and the schedule second".
The same happens for Escalation Policies and Services. If I have a Service S1 and Escalation Policy EP1, which is set to be the EP of S1, and then try to delete both resources, the provider will try to delete the Service first.
@stmcallister Are there any plans to fix this issue? 🙂
I hit the same today and landed here,
Error: DELETE API call to https://api.pagerduty.com/schedules/PUGT6GX failed 400 Bad Request. Code: 2001, Errors: [Schedule can't be deleted if it's being used by escalation policies], Message: Invalid Input Provided
Appreciate if you have any manual workaround at least if not a fix ?
No real workaround for me... sometimes running terraform apply
multiple times works (since it succeeds to delete some of the elements each time). Sometimes I do have to resort to manually fixing things.
Yeah, thanks. In my case, we wanted to replace the existing schedule associated to the Escalation policy with 2 new schedules. So I ended up editing those escalation policies through PD UI manually to add new schedules and remove older ones from it. Then I tried terraform plan again and it just had to remove the empty schedule so it was happy this time.
@noqcks @matan129 @AshutoshNirkhe @jashugan An update for fixing this issue was merged on #561 and It has been released in version v2.6.1 of PagerDuty TF Provider, so updating to the new version hopefully You all would be able to gracefully delete Schedules without getting stuck with into this error. Please if You find any further issues related with this error after updating don't hesitate on reopening this Issue ✌🏽
@imjaroiswebdev there are still two use cases. one will be solved in #564 and one is when the schedule is the only remaining one in an escalation policy. I think the example from this issue in particular is this case and is not solved. We would have to find another user or schedule to replace it, perhaps the account owner as a user?