IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
336 stars 646 forks source link

Panic crash with multiple resources #5349

Closed pauljegouic closed 1 month ago

pauljegouic commented 1 month ago

Hello @hkantare

As requested, here is the error we are encountering for few days now.

ibm_scc_profile_attachment.scc_profile_attachment_instance: Modifying... [id=e21215cd-71ba-4137-8cac-64caaa9ab0af/bfacb71d-4b84-41ac-9825-e8a3a3eb7405/56c6558c-57de-43e0-8ca0-aa82ae194f37]
╷
│ Error: Plugin did not respond
│ 
│   with ibm_scc_profile_attachment.scc_profile_attachment_instance,
│   on main.tf line 22, in resource "ibm_scc_profile_attachment" "scc_profile_attachment_instance":
│   22: resource "ibm_scc_profile_attachment" "scc_profile_attachment_instance" {
│ 
│ 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-ibm_v1.65.0 plugin:

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

goroutine 130 [running]:
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentMapToAttachmentsNotificationsPrototype(0x1400283e3f0?)
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:684 +0x408
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentUpdate({0x108ca7518, 0x140028acfc0}, 0x140028cca00, {0x108c4da40?, 0x140028f2000})
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:540 +0x73c
github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapFunction.func1({0x108ca7518?, 0x140028acfc0?}, 0x0?, {0x108c4da40?, 0x140028f2000?})
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1533 +0x34
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x140015b68c0, {0x108ca7550, 0x14001bcd590}, 0xd?, {0x108c4da40, 0x140028f2000})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:812 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140015b68c0, {0x108ca7550, 0x14001bcd590}, 0x14000b6da00, 0x140028cc480, {0x108c4da40, 0x140028f2000})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:919 +0x6a0
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14000f174b8, {0x108ca7550?, 0x14001bcd470?}, 0x14002111770)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:1060 +0xb70
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14000a5af00, {0x108ca7550?, 0x14001bcc5d0?}, 0x14002f22150)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:859 +0x3b8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x108ac6f00?, 0x14000a5af00}, {0x108ca7550, 0x14001bcc5d0}, 0x14002f220e0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140006bc3c0, {0x108cb22c0, 0x14000b5c4e0}, 0x14001b61c20, 0x140015776b0, 0x10ac9bd98, 0x0)
        google.golang.org/grpc@v1.57.1/server.go:1358 +0xc88
google.golang.org/grpc.(*Server).handleStream(0x140006bc3c0, {0x108cb22c0, 0x14000b5c4e0}, 0x14001b61c20, 0x0)
        google.golang.org/grpc@v1.57.1/server.go:1735 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.57.1/server.go:970 +0xb4
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.57.1/server.go:981 +0x174

Error: The terraform-provider-ibm_v1.65.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.

Note that we also had this issue with other resources:

 2024/05/13 12:08:41 Terraform apply |   29: resource "ibm_resource_instance" "secrets_manager" {
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | The plugin encountered an error, and failed to respond to the
 2024/05/13 12:08:41 Terraform apply | plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
 2024/05/13 12:08:41 Terraform apply | more details.
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | Stack trace from the terraform-provider-ibm_v1.65.0 plugin:
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | panic: runtime error: invalid memory address or nil pointer dereference
 2024/05/13 12:08:41 Terraform apply | [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x2337375]
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | goroutine 150 [running]:
 2024/05/13 12:08:41 Terraform apply | github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cloudshell.resourceIBMCloudShellAccountSettingsCreate({0x520ae18, 0xc000a0b380}, 0x1176592e000?, {0x4881360?, 0xc0003ac000})
 2024/05/13 12:08:41 Terraform apply |  github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cloudshell/resource_ibm_cloud_shell_account_settings.go:172 +0x6d5
 2024/05/13 12:08:41 Terraform apply | github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapFunction.func1({0x520ae18?, 0xc000a0b380?}, 0x0?, {0x4881360?, 0xc0003ac000?})
 2024/05/13 12:08:41 Terraform apply |  github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1533 +0x32
 2024/05/13 12:08:41 Terraform apply | github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0014cc9a0, {0x520ae50, 0xc001d77cb0}, 0xd?, {0x4881360, 0xc0003ac000})
 2024/05/13 12:08:41 Terraform apply |  github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:778 +0x12e
 2024/05/13 12:08:41 Terraform apply | github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0014cc9a0, {0x520ae50, 0xc001d77cb0}, 0xc001668000, 0xc00219ab00, {0x4881360, 0xc0003ac000})
 2024/05/13 12:08:41 Terraform apply |  github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:909 +0xa85
 2024/05/13 12:08:41 Terraform apply | github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0008b0150, {0x520ae50?, 0xc001d77b90?}, 0xc00085b900)
 2024/05/13 12:08:41 Terraform apply |  github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:1060 +0xe8d
 2024/05/13 12:08:41 Terraform apply | github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000a80280, {0x520ae50?, 0xc001d77380?}, 0xc002207880)
 2024/05/13 12:08:41 Terraform apply |  github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:859 +0x574
 2024/05/13 12:08:41 Terraform apply | github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x46fa0c0?, 0xc000a80280}, {0x520ae50, 0xc001d77380}, 0xc002207810, 0x0)
 2024/05/13 12:08:41 Terraform apply |  github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
 2024/05/13 12:08:41 Terraform apply | google.golang.org/grpc.(*Server).processUnaryRPC(0xc0006030e0, {0x5215c60, 0xc00148b1e0}, 0xc0007e58c0, 0xc001487740, 0x7267098, 0x0)
 2024/05/13 12:08:41 Terraform apply |  google.golang.org/grpc@v1.57.1/server.go:1358 +0xe23
 2024/05/13 12:08:41 Terraform apply | google.golang.org/grpc.(*Server).handleStream(0xc0006030e0, {0x5215c60, 0xc00148b1e0}, 0xc0007e58c0, 0x0)
 2024/05/13 12:08:41 Terraform apply |  google.golang.org/grpc@v1.57.1/server.go:1735 +0xa2f
 2024/05/13 12:08:41 Terraform apply | google.golang.org/grpc.(*Server).serveStreams.func1.1()
 2024/05/13 12:08:41 Terraform apply |  google.golang.org/grpc@v1.57.1/server.go:970 +0xca
 2024/05/13 12:08:41 Terraform apply | created by google.golang.org/grpc.(*Server).serveStreams.func1
 2024/05/13 12:08:41 Terraform apply |  google.golang.org/grpc@v1.57.1/server.go:981 +0x15c
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | Error: The terraform-provider-ibm_v1.65.0 plugin crashed!
pauljegouic commented 1 month ago
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply |   with module.landing_zone.module.iam_account_settings.module.iam_account_settings.ibm_cloud_shell_account_settings.cloud_shell_account_settings,
 2024/05/13 12:08:41 Terraform apply |   on .terraform/modules/landing_zone.iam_account_settings.iam_account_settings/main.tf line 39, in resource "ibm_cloud_shell_account_settings" "cloud_shell_account_settings":
 2024/05/13 12:08:41 Terraform apply |   39: resource "ibm_cloud_shell_account_settings" "cloud_shell_account_settings" {
 2024/05/13 12:08:41 Terraform apply | 
 2024/05/13 12:08:41 Terraform apply | The plugin encountered an error, and failed to respond to the
 2024/05/13 12:08:41 Terraform apply | plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
 2024/05/13 12:08:41 Terraform apply | more details.
 2024/05/13 12:08:41 Terraform apply | 
tyao117 commented 1 month ago

was able to reproduce your panic.

in your profile_attachment: can you put the notification block :

resource "ibm_scc_profile_attachment" "scc_profile_attachment_instance" {
  ...
  notifications {
    enabled = false
    controls {
      failed_control_ids = []
      threshold_limit = {any number like 15 or 999}
    }
  }
  ...
}
pauljegouic commented 1 month ago

Working workaround. Thanks @tyao117

tyao117 commented 1 month ago

Sure thing @pauljegouic, the attribute notifications is a Required attribute. I'm going to write a PR for a doc update.

ocofaigh commented 1 month ago

Reproduced with cloudshell in 1.65.1:

Stack trace from the terraform-provider-ibm_v1.65.1 plugin:

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

goroutine 151 [running]:
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cloudshell.resourceIBMCloudShellAccountSettingsCreate({0x520fd98, 0xc002404720}, 0x1176592e000?, {0x4885ea0?, 0xc000454000})
    github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/cloudshell/resource_ibm_cloud_shell_account_settings.go:172 +0x6dd
github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapFunction.func1({0x520fd98?, 0xc002404720?}, 0x0?, {0x4885ea0?, 0xc000454000?})
    github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1533 +0x32
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0015e7260, {0x520fdd0, 0xc001b65770}, 0xd?, {0x4885ea0, 0xc000454000})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:778 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0015e7260, {0x520fdd0, 0xc001b65770}, 0xc002417790, 0xc0017ee680, {0x4885ea0, 0xc000454000})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:909 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000c3a9c0, {0x520fdd0?, 0xc001b65320?}, 0xc002155b80)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:1060 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000b00000, {0x520fdd0?, 0xc001b64[630](https://github.com/terraform-ibm-modules/terraform-ibm-account-infrastructure-base/actions/runs/9126603347/job/25095369560#step:7:631)?}, 0xc00241c3f0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:859 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x46fe9e0?, 0xc000b00000}, {0x520fdd0, 0xc001b64630}, 0xc00241c380, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002243c0, {0x521abe0, 0xc000a0e680}, 0xc0019f4fc0, 0xc0015b36e0, 0x726d098, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1358 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc0002243c0, {0x521abe0, 0xc000a0e680}, 0xc0019f4fc0, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1735 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.57.1/server.go:970 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.57.1/server.go:981 +0x15c

Error: The terraform-provider-ibm_v1.65.1 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.
}
hkantare commented 1 month ago

We just added some extra check to avoid crash I think we still need for backend team to fix the issue

pauljegouic commented 1 month ago

1.66 fix, closing issue