terraform-provider-pagerduty
terraform-provider-pagerduty copied to clipboard
[Feature Request] Allow pagerduty_service_integration to modify CloudWatch "Correlate events by" and "Derive name from" options
I have not seen an option to allow modification of these two fields.
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?
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:
The rest of the fields matches the API, so maybe it is simply not documented?
There is an undocumented config
field sent in JSON payload to API when configuring e.g. CloudWatch integration
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.
Just adding my voice in to echo the sentiments above. It isn't a huge issue but it is mildly annoying.
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"
}
}
Changing these fields isn't supported yet...
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.