terraform-provider-opensearch icon indicating copy to clipboard operation
terraform-provider-opensearch copied to clipboard

[BUG] dashboard object cannot be created when index doesn't exist

Open foxlzl opened this issue 1 year ago • 3 comments

What is the bug?

A new dashboard object cannot be created if the assigned index doesn't exist. The terraform apply will fail saying plugin crash. However, if you check the indices in Opensearch, the given index actually got created from the failed deployment. If I rerun the Terraform plan and apply again, things would work as expected.

How can one reproduce the bug?

  1. make sure Opensearch does not have a test index for a tenant, say .kibana_<hash>_<tenant_name>
  2. use this provider to create an index pattern and assign this test index to that index pattern
  3. the deployment will fail with the following stack trace
  4. If we rerun terraform plan and apply again, we won't see the error, as the .kibana_<hash>_<tenant_name> index already got created from the first failed deployment.

│ 61: resource "opensearch_dashboard_object" "index_patterns" { │ │ 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-opensearch_v1.0.0 plugin: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xef475a] goroutine 147 [running]: github.com/opensearch-project/terraform-provider-opensearch/provider.elastic7CreateIndexIfNotExists(0xc00052ee00, {0xc00076f980, 0x15}, {0xc00076f980, 0x15}) github.com/opensearch-project/terraform-provider-opensearch/provider/resource_opensearch_dashboard_object.go:141 +0x21a github.com/opensearch-project/terraform-provider-opensearch/provider.resourceOpensearchDashboardObjectCreate(0xc0003fe600, {0xf84780?, 0xc000507400}) github.com/opensearch-project/terraform-provider-opensearch/provider/resource_opensearch_dashboard_object.go:100 +0x10f github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14565e8?, {0x14565e8?, 0xc0005366c0?}, 0xd?, {0xf84780?, 0xc000507400?}) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:330 +0x178 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00018b340, {0x14565e8, 0xc0005366c0}, 0xc00062b790, 0xc0003fe480, {0xf84780, 0xc000507400}) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:472 +0x83a github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000438798, {0x1456540?, 0xc0004eb000?}, 0xc00040d2c0) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xdaa github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0003f5c20, {0x14565e8?, 0xc000525ec0?}, 0xc0001f60e0) github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:812 +0x515 github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x111a540?, 0xc0003f5c20}, {0x14565e8, 0xc000525ec0}, 0xc000467a40, 0x0) github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0xc000170a80, {0x1459308, 0xc000445a00}, 0xc0008b70e0, 0xc00043b290, 0x1bdfee0, 0x0) google.golang.org/[email protected]/server.go:1282 +0xccf google.golang.org/grpc.(*Server).handleStream(0xc000170a80, {0x1459308, 0xc000445a00}, 0xc0008b70e0, 0x0) google.golang.org/[email protected]/server.go:1619 +0xa1b google.golang.org/grpc.(*Server).serveStreams.func1.2() google.golang.org/[email protected]/server.go:921 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/[email protected]/server.go:919 +0x28a Error: The terraform-provider-opensearch_v1.0.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.

What is the expected behavior?

It seems like the provider is trying to support creating an index pattern with a nonexistent index but it crashes after the index got created. If that is the case, the expected behavior should be the index patterns will be created successfully with a new index.

What is your host/environment?

Operating system, version.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

foxlzl avatar Apr 19 '23 23:04 foxlzl

@opensearch-project/opensearch-dashboards-core Could you please advise if this is a known issue from dashboards side?

rishabh6788 avatar Apr 25 '23 19:04 rishabh6788

Yes, a index pattern cannot be created before an index with that pattern exists. Why are we trying to create an index pattern before the index itself?

ashwin-pc avatar Apr 26 '23 06:04 ashwin-pc

Maybe the title of this bug is not clear. The point here is when we try to create an index pattern before the index, the index gets created but the index pattern creation fails. It seems like this use case, creating index pattern for a nonexistent index, is supposed to work but fails actually, otherwise the index won't be created at all, since I didn't explicitly create it.

foxlzl avatar May 01 '23 22:05 foxlzl