terraform-provider-pagerduty icon indicating copy to clipboard operation
terraform-provider-pagerduty copied to clipboard

Module doesn't understand the dependency between schedules and escalation policies

Open noqcks opened this issue 3 years ago • 6 comments

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

  1. Create a schedule linked to an escalation policy.
  2. Try delete both at the same time with tf apply

noqcks avatar May 20 '21 13:05 noqcks

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".

jashugan avatar May 21 '21 16:05 jashugan

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.

matan129 avatar Aug 31 '21 12:08 matan129

@stmcallister Are there any plans to fix this issue? 🙂

matan129 avatar Aug 31 '21 18:08 matan129

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 ?

AshutoshNirkhe avatar May 17 '22 06:05 AshutoshNirkhe

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.

matan129 avatar May 17 '22 07:05 matan129

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.

AshutoshNirkhe avatar May 17 '22 08:05 AshutoshNirkhe

@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 avatar Aug 25 '22 21:08 imjaroiswebdev

@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?

drastawi avatar Sep 06 '22 08:09 drastawi