PagerDuty / terraform-provider-pagerduty

Terraform PagerDuty provider
https://www.terraform.io/docs/providers/pagerduty/
Mozilla Public License 2.0
206 stars 210 forks source link

plugin crashes when importing incident workflows #809

Closed mfmbarros closed 7 months ago

mfmbarros commented 8 months ago

Hi there,

Whenever I try to import an incident workflow, either via terraform cli or import blocks, a runtime error occurs in Pagerduty plugin.

Terraform Version

tested versions: 1.5.7 , 1.7.1

Affected Resource(s)

Terraform Configuration Files

resource "pagerduty_incident_workflow" "my_slack_incident_workflow" {
  description = "Automatically name, create, and link Slack channels to the incident"
  name        = "Slack Channel"
  step {
    action = "pagerduty.com:incident-workflows:create-slack-channel:3"
    name   = "Create a Slack Channel for an Incident"

    input {
      name  = "Slack Team Name"
      value = var.slack_workspace_id
    }
    input {
      name  = "Desired Channel Name"
      value = "my-incident-{{incident.priority}}-{{incident.service.name}}-{{incident.incident_number}}"
    }
  }
}

import {
  to = pagerduty_incident_workflow.my_slack_incident_workflow
  id = "P5***KT"
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

https://gist.github.com/mfmbarros/2084baf4ad8ea37041ec996e5b323e74

Expected Behavior

Incident workflow imported with success.

Actual Behavior

Plugin crashes

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. create an incident workflow manually
  2. Import incident workflow with terraform plan or terraform import pagerduty_incident_workflow.my_slack_incident_workflow P5***KT
  3. Crash with panic output

References

viktor-f3 commented 8 months ago

The same problem here. Trying to migrate from response plays to workflows and the docs are lacking on how to configure steps to use escalation policies, so trying to import and compare the results.

Stack trace from the terraform-provider-pagerduty_v3.7.0 plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 63 [running]:
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.flattenIncidentWorkflowSteps(0xc0001a04d0, {0x277da70, 0x0, 0x1bace00?})
    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_incident_workflow.go:491 +0x637
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.flattenIncidentWorkflow(0xc000012368?, 0xc0001a04d0, 0x1, {0x277da70, 0x0, 0x0})
    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_incident_workflow.go:480 +0x118
github.com/terraform-providers/terraform-provider-pagerduty/pagerduty.fetchIncidentWorkflow.func1()
    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty/resource_pagerduty_incident_workflow.go:456 +0x33f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry.RetryContext.func1()
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/retry/wait.go:30 +0x56
github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry.(*StateChangeConf).WaitForStateContext.func1()
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/retry/state.go:113 +0x1c4
created by github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry.(*StateChangeConf).WaitForStateContext
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/retry/state.go:86 +0x1d8

Error: The terraform-provider-pagerduty_v3.7.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.