PagerDuty / terraform-provider-pagerduty

Terraform PagerDuty provider
https://www.terraform.io/docs/providers/pagerduty/
Mozilla Public License 2.0
204 stars 208 forks source link

Bug: Creating/updating a service with alert_grouping.type="time" leads to an API error "Invalid Input Provided" #887

Closed luca-bozzetto-depop closed 2 weeks ago

luca-bozzetto-depop commented 2 weeks ago

Terraform Version

Terraform v1.8.5
on darwin_arm64

Affected Resource(s)

pagerduty_service

Terraform Configuration Files

resource "pagerduty_service" "test_service" {
  name                    = "test-service"
  escalation_policy       = var.escalation_policy

  alert_grouping_parameters {
    type = "time"
    config {
      timeout = 15
    }
  }
}

Debug Output

https://gist.github.com/luca-bozzetto-depop/68ccb43f7d2147db18848755d3898b25

Expected Behavior

Creating or updating the alert_grouping_parameters settings for the type time for service in Terraform, should not result in an API error.

Actual Behavior

When creating or updating a service that uses the alert_grouping_parameters of type time, the TF-apply fails with an API error. According to the PD-API spec (https://developer.pagerduty.com/api-reference/fbc6e9f4ef8eb-update-a-service), it's not allowed to set the alert_grouping_parameters.config.time_window alert_grouping_parameters.config.aggregate properties when using "type=time", but the provider actually always adds this property, independently from the type attribute. Even though when setting alert_grouping_parameters.config.time_window to null, it's not omitted in the API-request.

I would assume that this has been introduced by a change/limitation on the PagerDuty-API side, this changelog seems to confirm it because a few days ago we were able to set such a configuration on some of our services (when updating them via Terraform). Today, it doesn't work anymore.

terraform will perform the following actions:

  # pagerduty_service.test_service will be updated in-place
  ~ resource "pagerduty_service" "test_service" {
        id                      = "PHV9J4Z"
        name                    = "test-service"

      ~ alert_grouping_parameters {
          + type = "time"

          + config {
              + timeout = 15
            }
        }

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

pagerduty_service.test_service: Modifying... [id=PHV9J4Z]
╷
│ Error: Error reading: PHV9J4Z: PUT API call to https://api.eu.pagerduty.com/services/PHV9J4Z failed 400 Bad Request. Code: 2001, Errors: [config has invalid fields.], Message: Invalid Input Provided
│ 
│   with pagerduty_service.test_service,
│   on service-test.tf line 1, in resource "pagerduty_service" "test_service":
│    1: resource "pagerduty_service" "test_service" {
│ 

Releasing state lock. This may take a few moments...

Steps to Reproduce

  1. create/update the pagerduty_service.test_service.alert_grouping_parameters.config.timeout property
  2. terraform apply