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

Cannot create incident_workflow_trigger that executes on incident creation

Open modwyer42 opened this issue 1 year ago • 2 comments

The implementation of the pagerduty_incident_workflow_trigger resource does not fully align to the API and prevents creation of triggers that execute on incident creation. Web UI example of this trigger definition: image

As per the API reference, in order to create a trigger that executes automatically on incident creation the condition value must be set to an empty string ("") with type set to conditional. image

The provider is not handling/nulling this empty string and so thinks that a condition was not provided, leading to it returning the error: image

A direct API POST successfully configures the desired trigger when using the following payload:

{
 "trigger_type": "conditional",
 "workflow": {
  "id": "PZXQRKC"
 },
 "services": [
  {
   "id": "PC9TV29"
  }
 ],
 "condition": ""
}

Terraform Version

Terraform v1.4.2 on linux_amd64

PagerDuty provider version: 2.11.2

Affected Resource(s)

  • pagerduty_incident_workflow_trigger

Terraform Configuration Files

_Note:- Simplified configuration example provided.

terraform {
  required_providers {
    pagerduty = {
      source  = "pagerduty/pagerduty"
      version = "~>2.9"
    }
  }
}

resource "pagerduty_incident_workflow" "example" {
  name         = "Example Incident Workflow"
  description  = "This Incident Workflow is an example"
  step {
    name           = "Send Status Update"
    action         = "pagerduty.com:incident-workflows:send-status-update:1"
    input {
      name = "Message"
      value = "Example status message sent on {{current_date}}"
    }
  }
}

resource "pagerduty_incident_workflow_trigger" "automatic_trigger" {
  workflow                   = pagerduty_incident_workflow.example.id
  type                       = "conditional"
  condition                  = ""
  subscribed_to_all_services = true
}

Debug Output

N/A

Expected Behavior

The provider should allow the explicit empty string to create an incident workflow trigger that executes on incident creation.

Actual Behavior

The provider is not handling/nulling this empty string and so thinks that a condition was not provided, leading to it returning the error: image

Steps to Reproduce

  1. Create a main.tf using the above example.
  2. Run terraform init
  3. Run terraform plan

The plan will error: image

modwyer42 avatar Apr 06 '23 05:04 modwyer42

For anyone looking to workaround this in the meantime, you can get equivalent behaviour to "When an incident is created" using the following condition: condition = "incident.status matches 'triggered'"

modwyer42 avatar Apr 11 '23 04:04 modwyer42

We have problem with this, in our case, using the last PD provider version 2.15.2 we're unable to fully create the incident workflow

Taking as example the code of this issue:

resource "pagerduty_incident_workflow" "example" {
  name         = "Example Incident Workflow"
  description  = "This Incident Workflow is an example"
  step {
    name           = "Send Status Update"
    action         = "pagerduty.com:incident-workflows:send-status-update:1"
    input {
      name = "Message"
      value = "Example status message sent on {{current_date}}"
    }
  }
}

This part is never configured on PD, and on each Terraform run it appears as new, it applies it but nothing in PagerDuty. This is a loop on each run. If we modify that in the UI it get replaced by an empty value each time that Terraform runs.

    input {
      name = "Message"
      value = "Example status message sent on {{current_date}}"
    }

mjimeneznet avatar Jul 28 '23 10:07 mjimeneznet