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

`pagerduty_service` does not rectify drift for `alert_grouping_parameters.config.timeout` #897

Open camlow325 opened 4 days ago

camlow325 commented 4 days ago

If the timeout for alert_grouping_parameters for a service is updated outside of Terraform, a subsequent Terraform apply may not be able to reconcile the difference and update PagerDuty with the intended value.

Terraform Version

› terraform -v
Terraform v1.9.0
on darwin_arm64
+ provider registry.terraform.io/pagerduty/pagerduty v3.14.4

Affected Resource(s)

Terraform Configuration Files

resource "pagerduty_service" "service" {
  name                    = "test"
  description             = "test"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 1800
  escalation_policy       = ...[omitted-for-brevity]...
  alert_creation          = "create_alerts_and_incidents"

  alert_grouping_parameters {
    type = "time"

    config {
      timeout = 60
    }
  }

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

Debug Output

Panic Output

Expected Behavior

Terraform plan shows that the timeout would be updated from 59 (currently in PagerDuty) back to 60 (in the Terraform code) and apply changes the value back to 60:

Terraform will perform the following actions:

  # pagerduty_service.service will be updated in-place
  ~ resource "pagerduty_service" "service" {
        id                      = "..."
        name                    = "test"
        # (12 unchanged attributes hidden)

      ~ alert_grouping_parameters {
            # (1 unchanged attribute hidden)

          ~ config {
              ~ timeout     = 59 -> 60
                # (3 unchanged attributes hidden)
            }
        }

        # (1 unchanged block 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.service: Modifying... [id=...]
pagerduty_service.service: Modifications complete after 1s [id=...]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Actual Behavior

Apply output shows the following:

pagerduty_service.service: Refreshing state... [id=...]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

A follow-up GET request to the PagerDuty API for the service shows that the timeout value remains 59 (set previously via the curl command) and not 60 (set in the Terraform code):

$ curl -v --request GET \
  --url https://api.pagerduty.com/services/[ID-of-service-created-by-Terraform] \
  --header 'Accept: application/json' \
  --header 'Authorization: Token token=...' \
  --header 'Content-Type: application/json'
{
  "service": {
    ...
    "alert_grouping": "time",
    "alert_grouping_timeout": 59,
    "alert_grouping_parameters": {
      "type": "time",
      "config": {
        "timeout": 59
      }
    },
    ...
} 

Steps to Reproduce

  1. terraform apply
  2. Store the JSON file below to a local file named test.json:
    {
    "service": {
    "acknowledgement_timeout": 1800,
    "alert_creation": "create_alerts_and_incidents",
    "alert_grouping": "time",
    "alert_grouping_timeout": 59,
    "alert_grouping_parameters": {
    "type": "time",
    "config": {
    "timeout": 59,
    "aggregate": ""
    }
    },
    "auto_resolve_timeout": 14400,
    "description": "test",
    "escalation_policy": {
    "id": "...[omitted for brevity]...",
    "type": "escalation_policy_reference"
    },
    "incident_urgency_rule": {
    "type": "constant",
    "urgency": "severity_based"
    },
    "name": "test"
    }
    }
  3. Terraform apply should be successful.
  4. Run the following command to update the timeout for the alert_grouping_parameters to 59:
$ curl -v --request PUT \
  --url https://api.pagerduty.com/services/[ID-of-service-created-by-Terraform] \
  --header 'Accept: application/json' \
  --header 'Authorization: Token token=...' \
  --header 'Content-Type: application/json' -d test.json
  1. API response should report that the timeout was updated to 59:
    {
    "service": {
    ...
    "alert_grouping": "time",
    "alert_grouping_timeout": 59,
    "alert_grouping_parameters": {
      "type": "time",
      "config": {
        "timeout": 59
      }
    },
    ...
    } 
  2. terraform apply

Important Factoids

References