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 delete user and remove it from all schedules at the same time #833

Open
Homulvas opened this issue Mar 8, 2024 · 2 comments
Open

Comments

@Homulvas
Copy link

Homulvas commented Mar 8, 2024

Terraform Version

1.7.4

Provider Version

3.9.0

Affected Resource(s)

Please list the resources as a list, for example:

  • pagerduty_user
  • pagerduty_schedule

Terraform Configuration Files

resource "pagerduty_schedule" "test_schedule" {
  name      = "Test schedule"
  time_zone = "Etc/UTC"
  layer {
    name                         = "Test"
    rotation_turn_length_seconds = 604800 # 7*24*60*60
    users = [
      pagerduty_user.test_user.id,
    ]
    start                  = "2024-02-25T23:00:00Z"
    rotation_virtual_start = "2024-02-25T23:00:00Z"
  }
}

resource "pagerduty_user" "test_user" {
  email = "test.user@test.com"
  name  = "Test User"
}

Expected Behavior

Schedule is updated first and user is deleted successfully.

Actual Behavior

Apply tries to delete the user first even though it has references.

pagerduty_user.test_user: Destroying... [id=P2FUWI1]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 10s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 20s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 30s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 40s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 50s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m0s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m10s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m20s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m30s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m40s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 1m50s elapsed]
pagerduty_user.test_user: Still destroying... [id=P2FUWI1, 2m0s elapsed]
╷
│ Error: DELETE API call to https://api.pagerduty.com/users/P2FUWI1 failed 400 Bad Request. Code: 0, Errors: [The user cannot be deleted as they have 1 schedule. Please remove the user from the following schedule to continue.], Message:
│
│
╵

Steps to Reproduce

  1. Delete the user and change the schedule to include some other user
  2. terraform apply
@lukaspj
Copy link
Contributor

lukaspj commented Mar 18, 2024

Hmm this one is interesting is this the failing case?

First apply this

resource "pagerduty_schedule" "test_schedule" {
  name      = "Test schedule"
  time_zone = "Etc/UTC"
  layer {
    name                         = "Test"
    rotation_turn_length_seconds = 604800 # 7*24*60*60
    users = [
      pagerduty_user.test_user_1.id,
    ]
    start                  = "2024-02-25T23:00:00Z"
    rotation_virtual_start = "2024-02-25T23:00:00Z"
  }
}

resource "pagerduty_user" "test_user_1" {
  email = "test.user.1@test.com"
  name  = "Test User 1"
}

resource "pagerduty_user" "test_user2" {
  email = "test.user.2@test.com"
  name  = "Test User 2"
}

Then this:

resource "pagerduty_schedule" "test_schedule" {
  name      = "Test schedule"
  time_zone = "Etc/UTC"
  layer {
    name                         = "Test"
    rotation_turn_length_seconds = 604800 # 7*24*60*60
    users = [
      pagerduty_user.test_user_2.id,
    ]
    start                  = "2024-02-25T23:00:00Z"
    rotation_virtual_start = "2024-02-25T23:00:00Z"
  }
}

resource "pagerduty_user" "test_user2" {
  email = "test.user.2@test.com"
  name  = "Test User 2"
}

?

@Homulvas
Copy link
Author

Yes. Something along these lines.

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

2 participants