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

[Bug]: The terraform-provider-pagerduty_v3.14.4 plugin crashed! #910

Open vividly789 opened 2 months ago

vividly789 commented 2 months ago

Terraform Version

Terraform v1.0.8
on linux_amd64
+ provider registry.terraform.io/pagerduty/pagerduty v3.14.4

Affected Resource(s)

Terraform Configuration Files

resource "pagerduty_service" "service" {
  name                    = "test"
  description             = "test"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 1800
  escalation_policy       = ...[omitted-for-brevity]...
  alert_creation          = "create_alerts_and_incidents"

  alert_grouping_parameters {
    type = "time"
    config {
      timeout = 60
    }
  }
}

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

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xd8 pc=0xe96f76]

goroutine 133 [running]:
github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.flattenService(0xc0000130f0?, 0x0)
    github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:576 +0x36
github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.resourcePagerDutyServiceUpdate(0xc000507400, {0xfffc60?, 0xc0002f0580?})
    github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_service.go:553 +0x216
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x14013e0?, {0x14013e0?, 0xc00040dd70?}, 0xd?, {0xfffc60?, 0xc0002f0580?})
    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(0xc0003e4c40, {0x14013e0, 0xc00040dd70}, 0xc000964dd0, 0xc000506e00, {0xfffc60, 0xc0002f0580})
    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(0xc00019faa0, {0x14013e0?, 0xc00040dc50?}, 0xc000888460)
    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(0x1401338?, {0x14013e0?, 0xc00040d920?}, 0xc000888460)
    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(0xc0003c8780, {0x14013e0?, 0xc00040d110?}, 0xc000138070)
    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({0x11210a0?, 0xc0003c8780}, {0x14013e0, 0xc00040d110}, 0xc000506900, 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(0xc000245000, {0x14013e0, 0xc00040d080}, {0x1406e38, 0xc0004bf1e0}, 0xc000886900, 0xc0004bc5a0, 0x1b0f138, 0x0)
    google.golang.org/grpc@v1.60.1/server.go:1372 +0xe49
google.golang.org/grpc.(*Server).handleStream(0xc000245000, {0x1406e38, 0xc0004bf1e0}, 0xc000886900)
    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.14.4 plugin crashed!

It looks like the provider is crashing here, while attempting to process the name attribute for the pagerduty_service resource:

d.Set("name", service.Name)

FWIW, it doesn't look from the Terraform plan like Terraform would have been trying to update the name attribute for the apply(checked the terraform plan for both failure one and successful one)

Debug Output

Below is a link to snippet of the last HTTP request the provider made before the crash:

https://gist.github.com/vividly789/46b96d4e28ef562f1812ca60fcd341f7

Looking in the debug log, I think this could have been caused by a PagerDuty API issue! But its worth erroring out more gracefully if the API returns an error that the provider handle, without crashing.

Panic Output

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0xd8 pc=0xe96f76]

Expected Behavior

Expect resource to be created during Terraform apply

Actual Behavior

I confirmed that terraform apply fails with the following message.

The plugin encountered an error, and failed to respond to the
plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
more details.

Stack trace from the terraform-provider-pagerduty_v3.14.4 plugin:
-----------------------mentioned above--------------------------

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

Steps to Reproduce

This appears to be an arbitrary error that only occurs sometimes when running terraform.

oponomarov-tu commented 1 month ago

Facing similar error when attempting to update pagerduty_escalation_policy. Provider version (3.11.4) hasn't changed in a while, we've been using it successfully until today.

Terraform Plan

```hcl Terraform will perform the following actions: # module.pagerduty.pagerduty_escalation_policy.team_oncall_escalation_policy[0] will be updated in-place ! resource "pagerduty_escalation_policy" "team_oncall_escalation_policy" { id = "" name = "team- Escalation Policy" # (3 unchanged attributes hidden) ! rule { ! escalation_delay_in_minutes = 60 -> 5 id = "" ! target { ! id = "" -> "" # (1 unchanged attribute hidden) } # (1 unchanged block hidden) } ! rule { ! escalation_delay_in_minutes = 15 -> 5 id = "" ! target { ! id = "" -> "" # (1 unchanged attribute hidden) } # (1 unchanged block hidden) } + rule { + escalation_delay_in_minutes = 60 + escalation_rule_assignment_strategy (known after apply) + target { + id = "" + type = "schedule_reference" } } + rule { + escalation_delay_in_minutes = 15 + escalation_rule_assignment_strategy (known after apply) + target { + id = "" + type = "schedule_reference" } } } Plan: 0 to add, 1 to change, 0 to destroy. ```

Logs

```hcl module.pagerduty.pagerduty_escalation_policy.team_oncall_escalation_policy[0]: Modifying... [id=] ╷ │ Error: Plugin did not respond │ │ with module.pagerduty.pagerduty_escalation_policy.team_oncall_escalation_policy[0], │ on ../../../modules/pd-on-call-team/escalation_policy.tf line 1, in resource "pagerduty_escalation_policy" "team_oncall_escalation_policy": │ 1: resource "pagerduty_escalation_policy" "team_oncall_escalation_policy" { │ │ The plugin encountered an error, and failed to respond to the │ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may │ contain more details. ╵ Stack trace from the terraform-provider-pagerduty_v3.11.4 plugin: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8ebc48] goroutine 24 [running]: github.com/PagerDuty/terraform-provider-pagerduty/pagerduty.resourcePagerDutyEscalationPolicyUpdate(0x4000773380, {0xa701c0?, 0x400071da40?}) github.com/PagerDuty/terraform-provider-pagerduty/pagerduty/resource_pagerduty_escalation_policy.go:248 +0x328 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xe5a660?, {0xe5a660?, 0x4000759080?}, 0xd?, {0xa701c0?, 0x400071da40?}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:800 +0x134 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x400032e0e0, {0xe5a660, 0x4000759080}, 0x40002a8b60, 0x4000773200, {0xa701c0, 0x400071da40}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:919 +0x670 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x400000d998, {0xe5a660?, 0x4000758f60?}, 0x400075a370) github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/grpc_provider.go:1074 +0xb5c github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0xe5a5b8?, {0xe5a660?, 0x4000758c30?}, 0x400075a370) github.com/hashicorp/terraform-plugin-mux@v0.13.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x184 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x4000366140, {0xe5a660?, 0x4000758240?}, 0x40001ec000) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/tf5server/server.go:859 +0x3b8 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xb88840?, 0x4000366140}, {0xe5a660, 0x4000758240}, 0x4000772000, 0x0) github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:503 +0x164 google.golang.org/grpc.(*Server).processUnaryRPC(0x40000c1a00, {0xe5a660, 0x40007581b0}, {0xe5fa98, 0x400043e000}, 0x4000760000, 0x400040e120, 0x150cbd8, 0x0) google.golang.org/grpc@v1.60.1/server.go:1372 +0xbec google.golang.org/grpc.(*Server).handleStream(0x40000c1a00, {0xe5fa98, 0x400043e000}, 0x4000760000) google.golang.org/grpc@v1.60.1/server.go:1783 +0xc7c google.golang.org/grpc.(*Server).serveStreams.func2.1() google.golang.org/grpc@v1.60.1/server.go:1016 +0x5c created by google.golang.org/grpc.(*Server).serveStreams.func2 google.golang.org/grpc@v1.60.1/server.go:1027 +0x144 Error: The terraform-provider-pagerduty_v3.11.4 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. ```

@cjgajard, can we kindly prioritise this? :) Would love to help you guys test it or provide more feedback.