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

"Intelligent" alert grouping type on pagerduty_service seems to require empty config block #550

Open DanielWeintraub opened 1 year ago

DanielWeintraub commented 1 year ago

Terraform Version

terraform 0.14.11

Affected Resource(s)

Terraform Configuration Files

within a pagerduty_service block

  alert_grouping_parameters {
    type = "intelligent"
    config {
      fields  = null
      timeout = 0
    }
  }

this used to work, but now returns:

module.monitoring.module.external_secrets.pagerduty_service.service: Creating...

Error: POST API call to https://api.pagerduty.com/services failed 400 Bad Request. Code: 2001, Errors: [Config is invalid.], Message: Invalid Input Provided

  on modules/pd_service/main.tf line 20, in resource "pagerduty_service" "service":
  20: resource "pagerduty_service" "service" {

It works fine if you remove the config block.

The documentation says:

If type is set to intelligent or empty then config can be empty.

BillSidney commented 1 year ago

Without the config block, terrafrom apply updates existing service in-place adding the config block every time applied

resource "pagerduty_service" "this" {
...
  # Enable Event Intelligence
  alert_grouping_parameters {
    type = "intelligent"
  }
}

$ terraform apply
...

# pagerduty_service.this will be updated in-place
  ~ resource "pagerduty_service" "this" {
        id                      = "XXXXXX"
        name                    = "ServiceDaemon"
        # (11 unchanged attributes hidden)
      ~ alert_grouping_parameters {
            # (1 unchanged attribute hidden)
          - config {
              - fields  = [] -> null
              - timeout = 0 -> null
            }
        }
        # (1 unchanged block hidden)
    }

Terraform Version: 1.2.3 pagerduty Version: 2.5.2

BillSidney commented 1 year ago

More Details - When attempting to change the description, updated in-place, using an empty config block fails.

 % terraform -version
     Terraform v1.2.3
     on darwin_amd64
# module.pagerduty_resource["XXXi"].pagerduty_service.this will be updated in-place
  ~ resource "pagerduty_service" "this" {
      ~ description             = <<-EOT
          ...
          - criticality: 0
          + criticality: 2

          - resiliency : 0
          + resiliency : 5
          ...

            Managed by Terraform
        EOT
        id                      = "XXXX"
        name                    = "xxxxxxx"
        # (11 unchanged attributes hidden)
        # (2 unchanged blocks hidden)
    }

│ Error: PUT API call to https://api.pagerduty.com/services/XXXXXX failed 400 Bad Request. Code: 2001, Errors: [Config is invalid.], Message: Invalid Input Provided

TF snippet:

terraform {
  required_version = ">= 1.2.3"

  required_providers {
    pagerduty = {
      source  = "pagerduty/pagerduty"
      version = "~> 2.5.2"
    }
}    

resource "pagerduty_service" "this" {

  name = var.name

  description = <<-EOT
    criticality  : ${var.serviceregistry.criticality}
    team         : ${var.serviceregistry.team_id}
    resiliency : ${var.serviceregistry.resiliency_score}
    gm            : ${var.teamworks.business_group}
    jira            : ${var.serviceregistry.jira}
    type          : ${var.serviceregistry.type}
    repo          : ${replace(replace(var.serviceregistry.repo_url, ".com:", ".com/"), "git@", "https://")}

    Managed by Terraform - https://${var.terraform_repository}
  EOT

  escalation_policy       = pagerduty_escalation_policy.this.id
  alert_creation          = "create_alerts_and_incidents"
  acknowledgement_timeout = "null"
  auto_resolve_timeout    = "null"

  # Enable Event Intelligence
  alert_grouping_parameters {
    type = "intelligent"
    config {}
  }

  # Enable Dynamic notifications based on alert severity
  incident_urgency_rule {
    type    = "constant"
    urgency = "severity_based"
  }
}