Skip to content

[Bug] data source elasticstack_elasticsearch_snapshot_repository panics if a repository for the provided name does not exist  #605

@breml

Description

@breml

Describe the bug
Data source elasticstack_elasticsearch_snapshot_repository panics if a repository for the provided name does not exist.

To Reproduce

  1. TF configuration
data "elasticstack_elasticsearch_snapshot_repository" "does_not_exist" {
  name = "does-not-exist"
}
  1. TF operations to execute to get the error: terraform plan
  2. Output:
╷
│ Error: Plugin did not respond                                                                                                                                                                                  │
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
Releasing state lock. This may take a few moments...

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

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

goroutine 68 [running]:
github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/cluster.dataSourceSnapRepoRead({0x16831a8, 0xc0003a44d0}, 0x0?, {0x1418280?, 0xc00011edd0?})
        github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/cluster/snapshot_repository_data_source.go:276 +0x19e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0003922a0, {0x1683100, 0xc000245710}, 0xd?, {0x1418280, 0xc00011edd0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.30.0/helper/schema/resource.go:795 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0003922a0, {0x1683100, 0xc000245710}, 0xc000691500, {0x1418280, 0xc00011edd0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.30.0/helper/schema/resource.go:1015 +0x149
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc00011b200, {0x1683100?, 0xc0002455c0?}, 0xc0007a8b20)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.30.0/helper/schema/grpc_provider.go:1249 +0x366
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadDataSource({{0x1689f80?, 0xc00011b200?}}, {0x1683100?, 0xc0002455c0?}, 0xc0007a8b00?)
        github.com/hashicorp/terraform-plugin-mux@v0.12.0/tf5to6server/tf5to6server.go:108 +0x1f8
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadDataSource(0x1683138?, {0x1683100?, 0xc0002451d0?}, 0xc0007a8b00)
        github.com/hashicorp/terraform-plugin-mux@v0.12.0/tf6muxserver/mux_server_ReadDataSource.go:36 +0x19f
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadDataSource(0xc0002ac0a0, {0x1683100?, 0xc0002444e0?}, 0xc0006c6190)
        github.com/hashicorp/terraform-plugin-go@v0.19.1/tfprotov6/tf6server/server.go:697 +0x3de
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadDataSource_Handler({0x1438120?, 0xc0002ac0a0}, {0x1683100, 0xc0002444e0}, 0xc000691100, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.1/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:503 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000ac000, {0x1683100, 0xc000244450}, {0x1688a00, 0xc000007ba0}, 0xc0000e99e0, 0xc0003fa8a0, 0x2113f68, 0x0)
        google.golang.org/grpc@v1.59.0/server.go:1343 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc0000ac000, {0x1688a00, 0xc000007ba0}, 0xc0000e99e0)
        google.golang.org/grpc@v1.59.0/server.go:1737 +0xc4c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.59.0/server.go:986 +0x86
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 22
        google.golang.org/grpc@v1.59.0/server.go:997 +0x145

Error: The terraform-provider-elasticstack_v0.11.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.

Expected behavior
Terraform plugin should not crash or panic in such a case but return a meaning full error instead.

Versions (please complete the following information):

  • OS: Linux (Ubuntu) within WSL
  • Terraform Version: 1.7.4
  • Provider version: 0.11.0 (tested with 0.11.2 as well, same problem)
  • Elasticsearch Version: 8.11.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions