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

Cannot destroy pagerduty_schedule. You must first resolve the following incidents related with Escalation Policies #619

Closed
fadeltd opened this issue Jan 24, 2023 · 2 comments

Comments

@fadeltd
Copy link

fadeltd commented Jan 24, 2023

Terraform Version

I'm using atlantis https://github.com/runatlantis/atlantis/blob/6b3b6b4b40a0dc6d44f39c0e9f5c55b6b96cd8e4/Dockerfile#L16

  • Terraform v1.3.5
  • provider registry.terraform.io/pagerduty/pagerduty v2.9.2

Affected Resource(s)

  • pagerduty_schedule

Terraform Configuration Files

resource "pagerduty_service" "team_name" {
  name                    = "team_name"
  escalation_policy       = pagerduty_escalation_policy.team_escalation.id
  alert_creation          = "create_alerts_and_incidents"
  auto_resolve_timeout    = 3600 * 24
  acknowledgement_timeout = "null"

  incident_urgency_rule {
    type    = "constant"
    urgency = "severity_based"
  }
}

resource "pagerduty_escalation_policy" "team_escalation" {
  name = "team_escalation"

  rule {
    escalation_delay_in_minutes = 15

    target {
      type = "schedule_reference"
      id   = pagerduty_schedule.team_primary.id
    }
  }

  # rule {
  #   escalation_delay_in_minutes = 15

  #   target {
  #     type = "schedule_reference"
  #     id   = pagerduty_schedule.team_secondary.id
  #   }
  # }
}

resource "pagerduty_schedule" "team_primary" {
  name      = "team_primary"
  time_zone = "Asia/Jakarta"

  layer {
    name                         = "primary"
    start                        = "2022-11-28T01:00:00+00:00"
    rotation_virtual_start       = "2022-11-28T01:00:00+00:00"
    rotation_turn_length_seconds = 3600 * 24 * 7 * 1
    users                        = ["PE3M...", "P20E..."]
  }
}

# resource "pagerduty_schedule" "team_secondary" {
#   name      = "team_secondary"
#   time_zone = "Asia/Jakarta"
# 
#   layer {
#     name                         = "secondary"
#     start                        = "2022-11-28T01:00:00+00:00"
#     rotation_virtual_start       = "2022-11-28T01:00:00+00:00"
#     rotation_turn_length_seconds = 3600 * 24 * 7 * 1
#     users                        = ["PE3M...", "P20E..."]
#   }
# }

Debug Output

  • Plan:
pagerduty_schedule.team_secondary: Refreshing state... [id=PYB8...]
pagerduty_schedule.team_primary: Refreshing state... [id=PE4D...]
pagerduty_escalation_policy.team_escalation: Refreshing state... [id=PD3Z...]
pagerduty_service.team_name: Refreshing state... [id=PARY...]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
  - destroy

Terraform will perform the following actions:

  # pagerduty_schedule.team_primary will be updated in-place
!   resource "pagerduty_schedule" "team_primary" {
        id             = "PE4D..."
        name           = "team_primary"
        # (4 unchanged attributes hidden)

!       layer {
            id                           = "PROU..."
            name                         = "primary"
!           rotation_virtual_start       = "2022-06-17T08:00:00+07:00" -> "2022-11-28T01:00:00+00:00"
!           users                        = [
                # (2 unchanged elements hidden)
            ]
            # (3 unchanged attributes hidden)
        }
    }

  # pagerduty_schedule.team_secondary will be destroyed
  # (because pagerduty_schedule.team_secondary is not in configuration)
-   resource "pagerduty_schedule" "team_secondary" {
-       description    = "Managed by Terraform" -> null
-       final_schedule = [
-           {
-               name                         = "Final Schedule"
-               rendered_coverage_percentage = "0.00"
            },
        ] -> null
-       id             = "PYB8..." -> null
-       name           = "team_secondary" -> null
-       teams          = [] -> null
-       time_zone      = "Asia/Jakarta" -> null

-       layer {
-           id                           = "PK7M..." -> null
-           name                         = "secondary" -> null
-           rendered_coverage_percentage = "0.00" -> null
-           rotation_turn_length_seconds = 604800 -> null
-           rotation_virtual_start       = "2022-11-28T08:00:00+07:00" -> null
-           start                        = "2023-01-18T17:12:53+07:00" -> null
-           users                        = [
-              "PE3M...",
-              "P20E...",
            ] -> null
        }
    }

Plan: 0 to add, 1 to change, 1 to destroy.
  • Apply:
pagerduty_schedule.team_secondary: Destroying... [id=PYB8...]
pagerduty_schedule.team_primary: Modifying... [id=PE4D...]
pagerduty_schedule.team_primary: Modifications complete after 1s [id=PE4D...]

Error: Before Removing Schedule "PYB8..." You must first resolve the following incidents related with Escalation Policies using this Schedule... 
https://domain.pagerduty.com/incidents/Q3FU...
https://domain.pagerduty.com/incidents/Q29B...
https://domain.pagerduty.com/incidents/Q17I...
https://domain.pagerduty.com/incidents/Q2ML...
https://domain.pagerduty.com/incidents/Q3YC...
...

Panic Output

N/A

Expected Behavior

The pagerduty_schedule should be deleted without issue.

Actual Behavior

The schedule cannot be deleted even tho it isn't related to any escalation policy or incident.

Steps to Reproduce

  1. terraform plan
  2. terraform apply

Additional Notes

  • The schedule can be deleted just fine via PagerDuty dashboard https://domain.pagerduty.com/schedules#PYB8... > 🗑️ Delete this schedule or via PagerDuty API. But it always failed when trying to delete via terraform.
  • The incidents mentioned aren't related in any way to the schedule that is being destroyed. The escalation policy that is being referenced by the incidents mentioned isn't the one using the schedule. The incidents are on other services' escalation policy.
  • I have also tried creating a new service, escalation policy, and schedules. Even tho it doesn't have any integration or incident, it always fails whenever I tried to delete the schedule. If I have any active open incidents.
    Empty Incident
  • The other resources can be deleted just fine
@lpmi-13
Copy link

lpmi-13 commented Jan 30, 2023

We're seeing the same behavior when there are any incidents open, even if they aren't related to the schedule we're trying to delete.

What's even stranger is that it won't delete the schedule even after we've successfully deleted the escalation policy attached to that schedule.

We see the same message about "You must first resolve the following incidents related with Escalation Policies using this Schedule..." even though the schedule is no longer associated with any escalation policies.

@imjaroiswebdev
Copy link
Contributor

@fadeltd @lpmi-13 Hey folk! Solution for this issue has been shipped on release cut v2.10.2 of PagerDuty Terraform Provider. Please don't hesitate on reopening this issue if you are still facing it after doing the upgrade ✌🏽 🎉 💪🏽

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

No branches or pull requests

3 participants