Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Panic from provider on empty template block in elasticstack_elasticsearch_index_template resource #417

Closed
nkvoll opened this issue Sep 6, 2023 · 1 comment · Fixed by #598
Labels
bug Something isn't working
Milestone

Comments

@nkvoll
Copy link
Member

nkvoll commented Sep 6, 2023

Describe the bug

If template {} is present in an elasticstack_elasticsearch_index_template resource, the provider plugin crashes.

To Reproduce

Apply the following resource:

    resource "elasticstack_elasticsearch_index_template" "my_index_template" {
        name           = "my_index_template"
        priority       = 500

        index_patterns = [
            "my_index_template-*",
        ]
        template {}
    }

Expected behavior

Success

** Actual behavior **

Terraform will perform the following actions:

  # elasticstack_elasticsearch_index_template.my_index_template will be created
  + resource "elasticstack_elasticsearch_index_template" "my_index_template" {
      + composed_of    = (known after apply)
      + id             = (known after apply)
      + index_patterns = [
          + "my_index_template*",
        ]
      + name           = "my_index_template"
      + priority       = 500

      + template {}
    }

Plan: 1 to add, 0 to change, 0 to destroy.
elasticstack_elasticsearch_index_template.my_index_template: Creating...
╷
│ Error: Plugin did not respond
│
│   with elasticstack_elasticsearch_index_template.my_index_template,
│   on index_templates.tf line 19, in resource "elasticstack_elasticsearch_index_template" "my_index_template":
│   19: resource "elasticstack_elasticsearch_index_template" "my_index_template" {
│
│ 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-elasticstack_v0.7.0 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 58 [running]:
github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/index.resourceIndexTemplatePut({0xfa1c08, 0x40001ca030}, 0x0?, {0xd69940, 0x40002cae70})
	github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/index/template.go:262 +0xda4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x4000365dc0, {0xfa1c40, 0x40004e9a10}, 0xd?, {0xd69940, 0x40002cae70})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:707 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x4000365dc0, {0xfa1c40, 0x40004e9a10}, 0x4000465790, 0x40003b3c80, {0xd69940, 0x40002cae70})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/resource.go:837 +0x85c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x400011b2a8, {0xfa1c40?, 0x40004e98f0?}, 0x4000711180)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:1021 +0xb5c
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ApplyResourceChange({0x4000393050, 0x40002957d0, 0x4000393080, 0x40003930b0, {0x4000383540, 0x1, 0x1}}, {0xfa1c40?, 0x40004e95c0?}, 0x4000711180)
	github.com/hashicorp/terraform-plugin-mux@v0.11.1/tf5muxserver/mux_server_ApplyResourceChange.go:30 +0x100
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x40002f14a0, {0xfa1c40?, 0x40004e8bd0?}, 0x400013c850)
	github.com/hashicorp/terraform-plugin-go@v0.17.0/tfprotov5/tf5server/server.go:821 +0x3b8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd974e0?, 0x40002f14a0}, {0xfa1c40, 0x40004e8bd0}, 0x400013c7e0, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.17.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:422 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x400026e1e0, {0xfa5c60, 0x4000003860}, 0x40004e70e0, 0x400045aed0, 0x18d4ea0, 0x0)
	google.golang.org/grpc@v1.56.1/server.go:1337 +0xc28
google.golang.org/grpc.(*Server).handleStream(0x400026e1e0, {0xfa5c60, 0x4000003860}, 0x40004e70e0, 0x0)
	google.golang.org/grpc@v1.56.1/server.go:1714 +0x80c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
	google.golang.org/grpc@v1.56.1/server.go:959 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.56.1/server.go:957 +0x164

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

If I remove the template { } block from the resource, it works as expected. Why did I have an empty template block in there? It's what I got when using terraform import to scaffold the resource :)

@nkvoll nkvoll added the bug Something isn't working label Sep 6, 2023
@anontrex
Copy link

anontrex commented Feb 6, 2024

+1 this is true for component templates resource files also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants