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

Pagerduty Provider Plugin Crashed #844

Closed defiant214 closed 5 months ago

defiant214 commented 6 months ago

Terraform Version

1.7.5

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

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

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 487 [running]: github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.expandIncidentUrgencyType(...) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:772 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.expandIncidentUrgencyRule({0xf0ee40?, 0xc00074e558?}) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:741 +0x4d4 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.buildServiceStruct(0xc000532320?) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:439 +0x805 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.resourcePagerDutyServiceUpdate(0xc000998200, {0xf8c460?, 0xc000532320?}) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:529 +0x58 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).update(0x1375c40?, {0x1375c40?, 0xc0000c86c0?}, 0xd?, {0xf8c460?, 0xc000532320?}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:800 +0x178 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).Apply(0xc000358e00, {0x1375c40, 0xc0000c86c0}, 0xc000992d00, 0xc000998000, {0xf8c460, 0xc000532320}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:919 +0x845 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ApplyResourceChange(0xc00012f980, {0x1375c40?, 0xc0000c8540?}, 0xc000b34be0) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/grpc_provider.go:1074 +0xe8d github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(muxServer).ApplyResourceChange(0x1375b98?, {0x1375c40?, 0xc0000c81e0?}, 0xc000b34be0) github.com/hashicorp/terraform-plugin-mux@v0.13.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x1b5 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ApplyResourceChange(0xc0003921e0, {0x1375c40?, 0xc000394990?}, 0xc000266070) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/tf5server/server.go:859 +0x574 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10a4bc0?, 0xc0003921e0}, {0x1375c40, 0xc000394990}, 0xc000540000, 0x0) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:503 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0xc0001c9000, {0x1375c40, 0xc000394900}, {0x137b038, 0xc000583040}, 0xc00079c000, 0xc00043e120, 0x1a3ce38, 0x0) google.golang.org/grpc@v1.60.1/server.go:1372 +0xe49 google.golang.org/grpc.(Server).handleStream(0xc0001c9000, {0x137b038, 0xc000583040}, 0xc00079c000) google.golang.org/grpc@v1.60.1/server.go:1783 +0x1031 google.golang.org/grpc.(Server).serveStreams.func2.1() google.golang.org/grpc@v1.60.1/server.go:1016 +0x68 created by google.golang.org/grpc.(*Server).serveStreams.func2 google.golang.org/grpc@v1.60.1/server.go:1027 +0x12e

imjaroiswebdev commented 6 months ago

Hi @defiant214 could you please provide us with a TF code snippet of the configuration you are trying to apply to face this error? Because We haven't been able to replicate it. Thanks in advance 🙏🏽

defiant214 commented 6 months ago
  resource "pagerduty_service" "this" {
  for_each = var.services

  name                    = each.value.name
  description             = try(each.value.description, null)
  auto_resolve_timeout    = try(each.value.auto_resolve_timeout, null)
  acknowledgement_timeout = try(each.value.acknowledgement_timeout, null)
  escalation_policy       = pagerduty_escalation_policy.this[each.value.escalation_policy].id
  response_play           = try(each.value.response_play, null)
  alert_creation          = try(each.value.alert_creation, null)

  dynamic "alert_grouping_parameters" {
    for_each = each.value.alert_grouping_parameters != null ? [each.value.alert_grouping_parameters] : []
    content {
      type = try(alert_grouping_parameters.value.type, null)

      dynamic "config" {
        for_each = alert_grouping_parameters.value.config != null ? [alert_grouping_parameters.value.config] : []
        content {
          timeout     = try(config.value.timeout, null)
          aggregate   = try(config.value.aggregate, null)
          fields      = try(config.value.fields, null)
          time_window = try(config.value.time_window, null)
        }
      }
    }
  }

import {
  for_each = { for service, attrs in var.services : service => attrs if attrs.id != null }
  to       = pagerduty_service.this[each.key]
  id       = each.value.id
}

variable "services" {
  description = "Technical services to create"
  type = map(object({
    name                    = string
    description             = optional(string)
    auto_resolve_timeout    = optional(string)
    acknowledgement_timeout = optional(string)
    escalation_policy       = string
    response_play           = optional(string)
    alert_creation          = optional(string)
    alert_grouping_parameters = optional(object({
      type = optional(string)
      config = optional(object({
        timeout     = optional(number)
        aggregate   = optional(string)
        fields      = optional(list(string))
        time_window = optional(number)
      }), {})
    }), {})
    auto_pause_notifications_parameters = optional(object({
      enabled = optional(bool)
      timeout = optional(number)
    }), {})
    incident_urgency_rule = optional(object({
      type    = optional(string)
      urgency = optional(string)
      during_support_hours = optional(object({
        type    = optional(string)
        urgency = optional(string)
      }), {})
      outside_support_hours = optional(object({
        type    = optional(string)
        urgency = optional(string)
      }), {})
    }), {})
    support_hours = optional(object({
      type         = optional(string)
      time_zone    = optional(string)
      days_of_week = optional(list(number))
      start_time   = optional(string)
      end_time     = optional(string)
    }), {})
    scheduled_actions = optional(object({
      type       = optional(string)
      to_urgency = optional(string)
      at = optional(object({
        type = optional(string)
        name = optional(string)
      }), {})
    }), {})
    slack_channel           = string
    id                      = optional(string)
    extension_servicenow_id = optional(string)
  }))
}

Sample input from input.tfvars.json:

{
  "services": {
      "test_service": {
      "name": "Test",
      "description": "Test",
      "auto_resolve_timeout": "null",
      "acknowledgement_timeout": "null",
      "escalation_policy": "my_group",
      "alert_creation": "create_alerts_and_incidents",
      "alert_grouping_parameters": {
        "type": "intelligent",
        "config": {
          "time_window": 300
        }
      },
      "incident_urgency_rule": {
        "type": "constant",
        "urgency": "severity_based"
      },
      "id": "PK0UT1C"
    }
  }
}

The plan was successful and indicated no issues. When I applied, the panic occurred.

imjaroiswebdev commented 5 months ago

Please upgrade to PagerDuty Terraform provider v3.11.2 or newer to stop facing this issue. Thanks for your patience and feedback.

defiant214 commented 5 months ago

The issue is still not fixed in v.3.11.2: Stack trace from the terraform-provider-pagerduty_v3.11.2 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 119 [running]: github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.expandScheduledActionAt(...) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:895 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.expandScheduledActions(...) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:870 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.buildServiceStruct(0xc0003923c0?) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:446 +0xe57 github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.resourcePagerDutyServiceUpdate(0xc000633180, {0xf8c460?, 0xc0003923c0?}) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:529 +0x58 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).update(0x1375d40?, {0x1375d40?, 0xc00078a060?}, 0xd?, {0xf8c460?, 0xc0003923c0?}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:800 +0x178 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Resource).Apply(0xc000358e00, {0x1375d40, 0xc00078a060}, 0xc0006bd450, 0xc000632f80, {0xf8c460, 0xc0003923c0}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:919 +0x845 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ApplyResourceChange(0xc00012f980, {0x1375d40?, 0xc0006f9bf0?}, 0xc000614640) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/grpc_provider.go:1074 +0xe8d github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(muxServer).ApplyResourceChange(0x1375c98?, {0x1375d40?, 0xc0006f8ea0?}, 0xc000614640) github.com/hashicorp/terraform-plugin-mux@v0.13.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x1b5 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ApplyResourceChange(0xc0003921e0, {0x1375d40?, 0xc0006f84b0?}, 0xc0002080e0) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/tf5server/server.go:859 +0x574 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10a4bc0?, 0xc0003921e0}, {0x1375d40, 0xc0006f84b0}, 0xc000632780, 0x0) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:503 +0x170 google.golang.org/grpc.(Server).processUnaryRPC(0xc0001c7000, {0x1375d40, 0xc0006f8210}, {0x137b138, 0xc0000076c0}, 0xc0006e7200, 0xc00043e120, 0x1a3ce38, 0x0) google.golang.org/grpc@v1.60.1/server.go:1372 +0xe49 google.golang.org/grpc.(Server).handleStream(0xc0001c7000, {0x137b138, 0xc0000076c0}, 0xc0006e7200) google.golang.org/grpc@v1.60.1/server.go:1783 +0x1031 google.golang.org/grpc.(Server).serveStreams.func2.1() google.golang.org/grpc@v1.60.1/server.go:1016 +0x68 created by google.golang.org/grpc.(*Server).serveStreams.func2 google.golang.org/grpc@v1.60.1/server.go:1027 +0x12e

Error: The terraform-provider-pagerduty_v3.11.2 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.

defiant214 commented 5 months ago

The issue still persists in v3.11.2. I am still getting plugin crashes.

On Wed, Apr 10, 2024 at 5:50 PM José Antonio Reyes @.***> wrote:

Please upgrade to PagerDuty Terraform provider v3.11.2 or newer to stop facing this issue. Thanks for your patience and feedback.

— Reply to this email directly, view it on GitHub https://github.com/PagerDuty/terraform-provider-pagerduty/issues/844#issuecomment-2048494159, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGD2ZRUPHPB4WO2LDYXRZBLY4WX2BAVCNFSM6AAAAABFX4JKPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBYGQ4TIMJVHE . You are receiving this because you were mentioned.Message ID: @.***>