terraform-provider-pagerduty icon indicating copy to clipboard operation
terraform-provider-pagerduty copied to clipboard

[Feature Request] Allow pagerduty_service_integration to modify CloudWatch "Correlate events by" and "Derive name from" options

Open NeckBeardPrince opened this issue 4 years ago • 5 comments

I have not seen an option to allow modification of these two fields.

image

NeckBeardPrince avatar Aug 11 '20 23:08 NeckBeardPrince

I'm interested in implementing this, but I need help. I can't see how you specify these fields in the raw API endpoint. Any maintainers able to point me in the right direction?

alexjurkiewicz avatar Aug 29 '20 21:08 alexjurkiewicz

I'd like to see the same for email integration as well (Alert keys & rules). But from the looks of it the API does not support it? Looking at the requests that the pagerduty webpage itself makes, one will see: Screenshot from 2021-01-05 09-22-26 The rest of the fields matches the API, so maybe it is simply not documented?

apollo13 avatar Jan 05 '21 08:01 apollo13

There is an undocumented config field sent in JSON payload to API when configuring e.g. CloudWatch integration screenshot

Yuxael avatar Mar 03 '21 11:03 Yuxael

Any chance for an update on this? As we're heavily reliant on Terraform-ing our PD services in tandem with our AWS infrastructure, we end up having a lot of PagerDuty incidents with somewhat meaningless titles going out to engineers like "GreaterThanOrEqualToThreshold 1.0" until they are able to dig in when already at their computers.

ryandzink avatar Dec 14 '21 13:12 ryandzink

Just adding my voice in to echo the sentiments above. It isn't a huge issue but it is mildly annoying.

JamesWhyley avatar Jan 05 '22 12:01 JamesWhyley

While this is not the prettiest solution and only a workaround, it works 😄

This snippet uses the undocumented config object on the integration update endpoint to set the incident_key and description option

provider "pagerduty" {
  token = var.pagerduty_token
}

data "pagerduty_vendor" "this" {
  name = "Cloudwatch"
}

resource "pagerduty_service_integration" "this" {
  name    = "My Test Integration"
  service = var.service_id
  vendor  = data.pagerduty_vendor.this.id
}

resource "null_resource" "this" {
  triggers = {
    service_id                     = var.service_id
    integration_id                 = pagerduty_service_integration.this.id
    cloudwatch_derive_description  = var.cloudwatch_derive_description
    cloudwatch_derive_incident_key = var.cloudwatch_derive_incident_key
  }

  provisioner "local-exec" {
    command = <<EOT
        response=$(curl --write-out "%%{http_code}" --silent --output /dev/null --request PUT 'https://api.pagerduty.com/services/${var.service_id}/integrations/${pagerduty_service_integration.this.id}' \
        --header 'Accept: application/vnd.pagerduty+json;version=2' \
        --header "User-Agent: Please implement https://github.com/PagerDuty/terraform-provider-pagerduty/issues/260" \
        --header 'Authorization: Token token=${var.pagerduty_token}' \
        --header 'Content-Type: application/json' \
        --data '{
            "integration": {
                "config": {
                    "fields": {
                        "incident_key": {
                            "value": "${var.cloudwatch_derive_incident_key}"
                        },
                        "description": {
                            "value": "${var.cloudwatch_derive_description}"
                        }
                    }
                }
            }
        }')  && [ $response -eq 200 ] || exit 1
    EOT
  }
}

variable "service_id" {
  type        = string
  description = "ID of the PagerDuty service in which the integration will be created"
}

variable "pagerduty_token" {
  type        = string
  description = "API token for PagerDuty"
}

variable "cloudwatch_derive_description" {
  type        = string
  description = "Where to derive the incident key from in the CloudWatch integration"
  default     = "alarm_description"

  validation {
    condition     = contains(["auto_generated", "alarm_name", "alarm_description"], var.cloudwatch_derive_description)
    error_message = "Must be one of auto_generated, alarm_name, alarm_description"
  }
}

variable "cloudwatch_derive_incident_key" {
  type        = string
  description = "Where to derive the incident key from in the CloudWatch integration"
  default     = "alarm_name"

  validation {
    condition     = contains(["alarm_name", "region", "source_origin", "always_create_new", "open_attach", "event_name", "finding_id"], var.cloudwatch_derive_incident_key)
    error_message = "Must be one of alarm_name, region, source_origin, always_create_new, open_attach, event_name, finding_id"
  }
}

janritter avatar Apr 05 '23 12:04 janritter

Changing these fields isn't supported yet...

skorobogatydmitry avatar Jul 12 '23 12:07 skorobogatydmitry

Unfortunately, at the moment, there's no way to achieve this utilizing the current REST API for creating new Service Integrations, in addition, there are no plans for adding this enhance to current API going forward, at least not during this year.

imjaroiswebdev avatar Feb 22 '24 17:02 imjaroiswebdev