opensearch-project / terraform-provider-opensearch

https://registry.terraform.io/providers/opensearch-project/opensearch
Apache License 2.0
73 stars 56 forks source link

[BUG] Not able to use the plugin is always crash on invalid memory address #130

Open mazerte opened 9 months ago

mazerte commented 9 months ago

What is the bug?

I tried to create a Dashboard visualization and an index pattern, and both are crashing in the same way.

How can one reproduce the bug?

provider "opensearch" {
    url                   = aws_opensearchserverless_collection.logs.collection_endpoint
    aws_signature_service = "aoss"
    healthcheck           = false
}

resource "opensearch_dashboard_object" "logs_index" {
  body = <<EOF
[
  {
    "_id": "index-pattern:logs",
    "_type": "doc",
    "_source": {
      "type": "index-pattern",
      "index-pattern": {
        "title": "logs-*",
        "timeFieldName": "@timestamp"
      }
    }
  }
]
EOF
}

What is the expected behavior?

Expect to create the index pattern in the saved objects.

What is your host/environment?

Terraform Cloud with AWS OpenSearch Serverless

Do you have any screenshots?

These are the logs the plugin gave me after crashing:

╷
│ Error: Plugin did not respond
│ 
│   with opensearch_dashboard_object.logs_index,
│   on data.tf line 637, in resource "opensearch_dashboard_object" "logs_index":
│  637: resource "opensearch_dashboard_object" "logs_index" {
│ 
│ 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_v2.1.0 plugin:

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

goroutine 52 [running]:
github.com/opensearch-project/terraform-provider-opensearch/provider.elastic7CreateIndexIfNotExists(0xc0000c7a40, {0xc000620267, 0x7}, {0xc000620267, 0x7})
        github.com/opensearch-project/terraform-provider-opensearch/provider/resource_opensearch_dashboard_object.go:130 +0x21a
github.com/opensearch-project/terraform-provider-opensearch/provider.resourceOpensearchDashboardObjectCreate(0xc000352e00, {0xe72a00?, 0xc0002502c0?})
        github.com/opensearch-project/terraform-provider-opensearch/provider/resource_opensearch_dashboard_object.go:94 +0xe7
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x13998a8?, {0x13998a8?, 0xc000334ab0?}, 0xd?, {0xe72a00?, 0xc0002502c0?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.12.0/helper/schema/resource.go:330 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000242e00, {0x13998a8, 0xc000334ab0}, 0xc0001e9450, 0xc000352c80, {0xe72a00, 0xc0002502c0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.12.0/helper/schema/resource.go:472 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000131ab8, {0x1399800?, 0xc0006224c0?}, 0xc0003362d0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.12.0/helper/schema/grpc_provider.go:1021 +0xdaa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002d35e0, {0x13998a8?, 0xc0003341e0?}, 0xc00034c000)
        github.com/hashicorp/terraform-plugin-go@v0.8.0/tfprotov5/tf5server/server.go:812 +0x515
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xfd2b00?, 0xc0002d35e0}, {0x13998a8, 0xc0003341e0}, 0xc0000a2420, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.8.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000226700, {0x139c5c8, 0xc00023b040}, 0xc00033e000, 0xc0001fab70, 0x1a80100, 0x0)
        google.golang.org/grpc@v1.45.0/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc000226700, {0x139c5c8, 0xc00023b040}, 0xc00033e000, 0x0)
        google.golang.org/grpc@v1.45.0/server.go:1619 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.45.0/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.45.0/server.go:919 +0x28a

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

Operation failed: failed running terraform apply (exit 1)

Do you have any additional context?

No

jordarlu commented 8 months ago

thanks for the issue @mazerte , @prudhvigodithi , please have a look , thanks a lot ~

benjefferies commented 8 months ago

Thanks for reporting @mazerte. To confirm I am experiencing the same bug trying to create the index-pattern

benjefferies commented 5 months ago

After investigating this a little further I think it has more to do with OpenSearch serverless rather than the provider. By default, the provider tries to look for a default index .kibana which does not not exist in OS serverless.

I think it's default in OS serverless, when I try to use the default index to store stuff, the API rejects when trying to store with an index, this could be because it's the wrong index to store dashboard stuff or it's a limitation with OS Serverless.

I've raised a support ticket with AWS to find out more and will feedback.