opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
100 stars 136 forks source link

Panic when importing an alert policy #360

Open gdlx opened 1 year ago

gdlx commented 1 year ago

Hi, I get a panic when importing an alert policy: https://gist.github.com/gdlx/19d7fcca60439d6c6b372e0db3a7addd

The import command is the following: terraform import opsgenie_alert_policy.add_tag 8a2e4b35-94ec-4192-a64f-f0ad52b8ef43

I have no issue to create/update/delete a policy, only when importing.

The alert policy template is the following:

resource "opsgenie_alert_policy" "add_tag" {
  name               = "Add Tag test"
  team_id            = data.opsgenie_team.my_team.id
  policy_description = "Adds TEST tag to all alerts."
  message            = "{{message}}"
  continue_policy    = true
  enabled            = false

  filter {}
  tags = ["TEST"]
}

Terraform version: 1.3.7 Opsgenie provider version: 0.6.20

matthias-froomle commented 1 year ago

When importing via team_id/policy_id the same issue happens:

│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more
│ details.
╵

Stack trace from the terraform-provider-opsgenie_v0.6.28 plugin:

panic: interface conversion: error is *errors.errorString, not *client.ApiError

goroutine 29 [running]:
github.com/opsgenie/terraform-provider-opsgenie/opsgenie.resourceOpsGenieAlertPolicyRead({0x10122aa50?, 0x140004f2540?}, 0x14000606200, {0x1010f57c0?, 0x140001a9bf8?})
    github.com/opsgenie/terraform-provider-opsgenie/opsgenie/resource_opsgenie_alert_policy.go:357 +0xbd8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x14000432700, {0x10122aa50, 0x140004f2540}, 0x24?, {0x1010f57c0, 0x140001a9bf8})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:358 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x14000432700, {0x10122aa50, 0x140004f2540}, 0x1400020be10, {0x1010f57c0, 0x140001a9bf8})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:635 +0x30c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14000304768, {0x10122aa50, 0x140004f2540}, 0x140004f25c0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/grpc_provider.go:576 +0x3d8
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x14000345080, {0x10122aaf8?, 0x14000602210?}, 0x14000300f00)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:553 +0x310
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x1011f5c20?, 0x14000345080}, {0x10122aaf8, 0x14000602210}, 0x14000300ea0, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:344 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000330700, {0x10122e900, 0x14000208480}, 0x140004c8100, 0x14000470300, 0x1016b1c90, 0x0)
    google.golang.org/grpc@v1.32.0/server.go:1194 +0xaf0
google.golang.org/grpc.(*Server).handleStream(0x14000330700, {0x10122e900, 0x14000208480}, 0x140004c8100, 0x0)
    google.golang.org/grpc@v1.32.0/server.go:1517 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.32.0/server.go:859 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.32.0/server.go:857 +0x298

Error: The terraform-provider-opsgenie_v0.6.28 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.

I am on provider version v0.6.28 with Terraform 1.0.4

matthias-froomle commented 1 year ago

Turned out I was importing a notification policy inside of a alert policy resource, so my issue is fixed, but maybe the provider shouldn't crash in this case