hashicorp / terraform-provider-helm

Terraform Helm provider
https://www.terraform.io/docs/providers/helm/
Mozilla Public License 2.0
998 stars 368 forks source link

helm provider 2.16.0 panics when destroy returns "release not found" #1500

Open sbocinec opened 2 hours ago

sbocinec commented 2 hours ago

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: `1.8.5`
Provider version: `2.16.0`
Kubernetes version: 1.29.8`

Affected Resource(s)

Terraform Configuration Files

Practically any helm_release

Debug Output

https://gist.github.com/sbocinec/12b7be3406ab5a68237ae7480191840a

Panic Output

Do you really want to destroy all resources?                                                                                                                   
  Terraform will destroy all your managed infrastructure, as shown above.                                                                                      
  There is no undo. Only 'yes' will be accepted to confirm.                                                                                                    

  Enter a value: yes                                                           

helm_release.kminion: Destroying... [id=kminion]
╷
│ Error: Plugin did not respond
│ 
│ 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-helm_v2.16.0_x5 plugin:

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

goroutine 42 [running]:
github.com/hashicorp/terraform-provider-helm/helm.resourceReleaseDelete({0x26ccb78?, 0xc0007a8240?}, 0xc000116a80, {0x21a9700?, 0xc000527540})
        github.com/hashicorp/terraform-provider-helm/helm/resource_release.go:872 +0x2c1
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).delete(0xc000268e00, {0x26ccb78, 0xc0007a8240}, 0xc000116a80, {0x21a9700, 0xc000527540})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:857 +0x119
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000268e00, {0x26ccb78, 0xc0007a8240}, 0xc0006dcf70, 0xc000116a00, {0x21a9700, 0xc000527540})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:906 +0x605
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0004abea8, {0x26ccb78?, 0xc0007a8180?}, 0xc000204aa0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xd5c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0005f60a0, {0x26ccb78?, 0xc0006f3740?}, 0xc0001ab810)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x22b0a60, 0xc0005f60a0}, {0x26ccb78, 0xc0006f3740}, 0xc0000d7800, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002d2000, {0x26ccb78, 0xc0006f36b0}, {0x26d8aa0, 0xc0005fc300}, 0xc0007997a0, 0xc00054afc0, 0x38ed318, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc0002d2000, {0x26d8aa0, 0xc0005fc300}, 0xc0007997a0)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 34
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x125

Error: The terraform-provider-helm_v2.16.0_x5 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.

Steps to Reproduce

  1. Have a helm_release resource successfully applied to a K8s cluster
  2. Delete the resource manually (e.g. helm uninstall release_name)
  3. Run terraform destroy -refresh=false

Expected Behavior

The destroy should ignore the release not found error and finish successfully

Actual Behavior

The destroy panics

Important Factoids

I have tested the same behavior on AKS & GKE, it panics reliably. The feature was introduced by me in https://github.com/hashicorp/terraform-provider-helm/pull/1487 so it must be either reverted or the nil pointer deref fixed :bow: -> I have meanwhile prepared a fix for the issue - GH-1501

References

Community Note

sbocinec commented 2 hours ago

Here is a fix for the issue https://github.com/hashicorp/terraform-provider-helm/pull/1501