yandex-cloud / terraform-provider-yandex

Terraform Yandex provider
https://www.terraform.io/docs/providers/yandex/
Mozilla Public License 2.0
213 stars 116 forks source link

A runtime error occurs during OpenSearch cluster deployment #403

Closed mtigoev closed 9 months ago

mtigoev commented 11 months ago

Hi there,

I have tried to deploy managed OpenSearch cluster using Yandex terraform provider, but encountered the following runtime error during terraform plan execution:

Stack trace from the terraform-provider-yandex_v0.104.0 plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 40 [running]:
github.com/yandex-cloud/terraform-provider-yandex/yandex.expandOpenSearchConfigCreateSpec({0x1c9bac0?, 0xc0011f2f78?})
    github.com/yandex-cloud/terraform-provider-yandex/yandex/mdb_opensearch_structures.go:107 +0x473
github.com/yandex-cloud/terraform-provider-yandex/yandex.opensearchNodeGroupsDiffCustomize({0x2657020?, 0xc00127bb90?}, 0x2320da2?, {0xd?, 0x2328589?})
    github.com/yandex-cloud/terraform-provider-yandex/yandex/mdb_opensearch_structures.go:643 +0x211
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0xc000c473e0, {0x2657020, 0xc00127bb90}, 0xc000da5450, 0xc001286f30, 0x23d67e8, {0x2041240, 0xc000b76f20}, 0x0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/schema.go:698 +0x4d4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0x2657db0?, {0x2657020?, 0xc00127bb90?}, 0xc000da5450, 0x1de3840?, {0x2041240?, 0xc000b76f20?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/resource.go:962 +0xe5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0xc000655278, {0x2657020?, 0xc00127b980?}, 0xc000fb8fa0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/grpc_provider.go:747 +0xa09
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.PlanResourceChange({{0x2661508?, 0xc000655278?}}, {0x2657020, 0xc00127b980}, 0x0?)
    github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf5to6server/tf5to6server.go:81 +0x5a
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.muxServer.PlanResourceChange({0xc000e01b00, 0xc0012d2fa0, 0xc000e01b30, 0xc000e01b60, {0xc000c9eac0, 0x2, 0x2}}, {0x2657020?, 0xc00127b650?}, 0xc000fb8f50)
    github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf6muxserver/mux_server_PlanResourceChange.go:66 +0x247
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).PlanResourceChange(0xc00065ebe0, {0x2657020?, 0xc00127a840?}, 0xc0003b8070)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov6/tf6server/server.go:784 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_PlanResourceChange_Handler({0x22377e0?, 0xc00065ebe0}, {0x2657020, 0xc00127a840}, 0xc00101a000, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:404 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0007c7c20, {0x2657020, 0xc00127a6f0}, {0x265fce0, 0xc000dec680}, 0xc0011b79e0, 0xc000ecf9e0, 0x3eadca8, 0x0)
    google.golang.org/grpc@v1.59.0/server.go:1343 +0xe49
google.golang.org/grpc.(*Server).handleStream(0xc0007c7c20, {0x265fce0, 0xc000dec680}, 0xc0011b79e0)
    google.golang.org/grpc@v1.59.0/server.go:1737 +0xca6
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.59.0/server.go:986 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.59.0/server.go:997 +0x15c

Error: The terraform-provider-yandex_v0.104.0 plugin crashed!

Terraform version:

Terraform v1.6.3
on linux_amd64
+ provider registry.terraform.io/yandex-cloud/yandex v0.104.0

It looks like openSearchList variable should be replaced by dashboardsList here:

    dashboardsList := d["dashboards"].([]interface{})
    if len(openSearchList) != 0 {
        dashboards := dashboardsList[0].(map[string]interface{})

        config.DashboardsSpec = &opensearch.DashboardsCreateSpec{
            NodeGroups: expandSchemaSet(
                dashboards["node_groups"].(*schema.Set),
                dashboardsCreateSpecNodeGroupExpander),
        }
    }

Thanks!

mtigoev commented 11 months ago

By the way, disk_size argument accept size in bytes, instead of gigabyte, like it pointed in documentation. I got the following error during test provider with fixes:

  │ Error: Error while requesting API to create OpenSearch Cluster: server-request-id = b735c9d2-0ab0-4bf9-9abe-c7719a73ef2c server-trace-id = 5315c679db36e0ef:1261d5ba74e2bed:5315c679db36e0ef:1 client-request-id = 4d2d6a3e-dc07-4f14-92ec-7aa2695630fd client-trace-id = 2a17c7cf-7f3c-4bda-b034-d995ec293ab2 rpc error: code = InvalidArgument desc = invalid disk size, must be inside [10737418240,4398046511105) range

So, I have changed disk_size to 10737418240 in configuration and got exactly 10Gb disk during deployment.

kvendingoldo commented 10 months ago

up! I have the same issue

saiks24 commented 10 months ago

Hi, mtigoev! Thanks for your interest in our product. We've just merged your PR to the master branch. Fix will be available with the next release.

saiks24 commented 9 months ago

Hi, mtigoev! We've merged your PR and it's available since the v0.107.0 version. Could you please notify us, if your issue has been resolved?

mtigoev commented 9 months ago

Hi, saiks24!

The fix should work. I have tested it on my own build of provider before I created the PR.

vladimir4862 commented 9 months ago

looks like this error still here for arm64

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x105987544]

goroutine 138 [running]:
github.com/yandex-cloud/terraform-provider-yandex/yandex.opensearchNodeGroupsDiffCustomize({0x106702700?, 0x140012fe3c0?}, 0x105bc59d8?, {0xd?, 0x105bcd255?})
    github.com/yandex-cloud/terraform-provider-yandex/yandex/mdb_opensearch_structures.go:650 +0x1a4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0x14000c3dc80, {0x106702700, 0x140012fe3c0}, 0x14001534820, 0x1400160f680, 0x1066c9b08, {0x1063ea4a0, 0x140009c3600}, 0x0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/schema.go:698 +0x3c4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0x106703500?, {0x106702700?, 0x140012fe3c0?}, 0x14001534820, 0x106184ee0?, {0x1063ea4a0?, 0x140009c3600?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/resource.go:962 +0x9c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0x14000147e60, {0x106702700?, 0x140012fe1b0?}, 0x140012e8870)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/grpc_provider.go:747 +0x850
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.PlanResourceChange({{0x10670c948?, 0x14000147e60?}}, {0x106702700, 0x140012fe1b0}, 0x0?)
    github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf5to6server/tf5to6server.go:81 +0x58
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.muxServer.PlanResourceChange({0x14000cd23f0, 0x14000e9a5c0, 0x14000cd2420, 0x14000cd2450, {0x14000a7cc40, 0x2, 0x2}}, {0x106702700?, 0x140012c3e60?}, 0x140012e8820)
    github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf6muxserver/mux_server_PlanResourceChange.go:66 +0x1c8
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).PlanResourceChange(0x140006a4e60, {0x106702700?, 0x140012c3470?}, 0x1400021d2d0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov6/tf6server/server.go:784 +0x3bc
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_PlanResourceChange_Handler({0x1065e9840?, 0x140006a4e60}, {0x106702700, 0x140012c3470}, 0x14000575480, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:404 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140009a7000, {0x106702700, 0x14001548000}, {0x10670b380, 0x1400063c1a0}, 0x14001525c20, 0x14000d622a0, 0x107f62a88, 0x0)
    google.golang.org/grpc@v1.60.1/server.go:1372 +0xc6c
google.golang.org/grpc.(*Server).handleStream(0x140009a7000, {0x10670b380, 0x1400063c1a0}, 0x14001525c20)
    google.golang.org/grpc@v1.60.1/server.go:1783 +0xc9c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.60.1/server.go:1016 +0x5c
created by google.golang.org/grpc.(*Server).serveStreams.func2
    google.golang.org/grpc@v1.60.1/server.go:1027 +0x148

Error: The terraform-provider-yandex_v0.107.0 plugin crashed!

if add dashboards in config block in resource yandex_mdb_opensearch_cluster all works correctly