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

The provider crashes when fields are explicitly set to null #522

Closed
mkonopi opened this issue Aug 2, 2022 · 3 comments · Fixed by #534
Closed

The provider crashes when fields are explicitly set to null #522

mkonopi opened this issue Aug 2, 2022 · 3 comments · Fixed by #534
Labels
bug Something isn't working

Comments

@mkonopi
Copy link

mkonopi commented Aug 2, 2022

Setting a field to null should be handled the same as if the field was not defined at all. Most places where the provider casts those fields into another type do not handle a nil value and cause the provider to crash.

For example, this deployment will cause a crash when expanding the kibana config

resource "ec_deployment" "tb-null-value" {
  region                 = "aws-eu-west-2"
  version                = data.ec_stack.eight-three.version
  deployment_template_id = "aws-cpu-optimized-arm-v4"

  elasticsearch {
    topology {
      id   = "hot_content"
      size = "2g"
    }
  }

  kibana {
    config {
      user_settings_yaml = null
    }

    topology {
      size       = "1g"
      zone_count = 1
    }
  }
}

Started having this error when deploying trough terraform:

│ Error: Plugin did not respond

│ with module.ec.ec_deployment.ec_cluster,
│ on .terraform/modules/ec/main.tf line 5, in resource "ec_deployment" "ec_cluster":
│ 5: resource "ec_deployment" "ec_cluster" {

│ 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-ec_v0.4.1 plugin:
panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 38 [running]:
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandEsTopology({0xeb9380, 0xc000522420}, {0xc00052a050, 0x7, 0x9})
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/elasticsearch_expanders.go:186 +0x8f7
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandEsResource({0xf48d40, 0xc0002de600}, 0xc00053d1d0)
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/elasticsearch_expanders.go:80 +0x276
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandEsResources({0xc000664190, 0x1, 0x15}, 0xc0001a4f60)
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/elasticsearch_expanders.go:51 +0xbc
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.updateResourceToModel(0x1a3bae8, 0xc00047c3c0)
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/expanders.go:179 +0x8bb
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.updateDeployment({0xc0005aef60, 0xc0005aeff8}, 0xc00058a680, 0xc00047c3c0)
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/update.go:53 +0x45
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.updateResource({0x1256748, 0xc00059dce0}, 0xc0005af030, {0xe9d960, 0xc00047c3c0})
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/update.go:36 +0x7d
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc0000d61c0, {0x1256780, 0xc0004fb800}, 0xd, {0xe9d960, 0xc00047c3c0})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:741 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0000d61c0, {0x1256780, 0xc0004fb800}, 0xc0004f21a0, 0xc00058b480, {0xe9d960, 0xc00047c3c0})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:847 +0x9e5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00047d140, {0x12566d8, 0xc0002dc1c0}, 0xc0004c6d20)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00042a1e0, {0x1256780, 0xc0004fb020}, 0xc000187810)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:812 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10993e0, 0xc00042a1e0}, {0x1256780, 0xc0004fb020}, 0xc00007e720, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00046afc0, {0x1266998, 0xc0001131e0}, 0xc000524a20, 0xc000346780, 0x1aa23e0, 0x0)
google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc00046afc0, {0x1266998, 0xc0001131e0}, 0xc000524a20, 0x0)
google.golang.org/[email protected]/server.go:1619 +0xa2a
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 +0x294
Error: The terraform-provider-ec_v0.4.1 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.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: command terminated with exit code 1

@mkonopi mkonopi added the bug Something isn't working label Aug 2, 2022
@tobio
Copy link
Member

tobio commented Aug 2, 2022

@mkonopi are you able to share your terraform module reproducing this issue?

@mkonopi
Copy link
Author

mkonopi commented Aug 12, 2022

@mkonopi are you able to share your terraform module reproducing this issue?

This happens once in a while and then there is not much I can do. Need to remove cluster from EC and run code again. I can see TF provider was last time updated 3 months ago.

Archive.zip
Added archive with our code:
terraform-elastic-cloud - this is module
elastic-cloud-prod - actual deployment using the module

@tobygale
Copy link

tobygale commented Sep 9, 2022

I can consistently create a similar error.

The terraform plan works as expected but terraform apply will fail as soon it begins the ec_deployment resource.

I have tried versions 4.0 and 4.1 of the provider and versions 1.1.3 and 1.2.9 of terraform itself and I get the same error:

module.my_cluster.ec_deployment.cluster: Creating...
╷
│ Error: Request cancelled
│ 
│   with module.my_cluster.ec_deployment.cluster,
│   on ../../modules/elasticsearch/main.tf line 14, in resource "ec_deployment" "cluster":
│   14: resource "ec_deployment" "cluster" {
│ 
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-ec_v0.4.1 plugin:

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

goroutine 113 [running]:
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandKibanaConfig({0xeb9380, 0xc00047d2c0}, 0xc0002a35e0)
        github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/kibana_expanders.go:131 +0x397
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandKibanaResource({0xf48d40, 0xc0005003c0}, 0xc0002e0100)
        github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/kibana_expanders.go:71 +0x25c
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.expandKibanaResources({0xc000315b30, 0x1, 0x15}, 0xc0002e0100)
        github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/kibana_expanders.go:43 +0xff
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.createResourceToModel(0x40, 0xc00047c4e0)
        github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/expanders.go:77 +0x738
github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource.createResource({0x1256748, 0xc000551680}, 0xc000267030, {0xe9d960, 0xc00047c4e0})
        github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource/create.go:36 +0xe7
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc00001e1c0, {0x1256780, 0xc000287080}, 0xd, {0xe9d960, 0xc00047c4e0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00001e1c0, {0x1256780, 0xc000287080}, 0xc000722000, 0xc000513480, {0xe9d960, 0xc00047c4e0})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:837 +0xc29
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00047d128, {0x12566d8, 0xc00050e780}, 0xc00014a3c0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0004301e0, {0x1256780, 0xc000286690}, 0xc000274230)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:812 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10993e0, 0xc0004301e0}, {0x1256780, 0xc000286690}, 0xc0005504e0, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00054e540, {0x1266998, 0xc00047ed00}, 0xc00070e000, 0xc0000cb620, 0x1aa23e0, 0x0)
        google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc00054e540, {0x1266998, 0xc00047ed00}, 0xc00070e000, 0x0)
        google.golang.org/[email protected]/server.go:1619 +0xa2a
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 +0x294

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

As you can see from the error, it mentions deploymentresource.expandKibanaConfig, and sure enough, if I disable Kibana on my deployment, it will work successfully.

I've had a look at the module provided by @mkonopi and I can see we are doing something very similar.

Here's how I am handling the kibana {} block I've written that goes inside the ec_deployment resource in my module:

# snip

  dynamic "kibana" {
    for_each = var.kibana_enabled == true ? [true] : []          # <--- provider seems to hate this?

    content {
      config {
        user_settings_yaml          = try(var.kibana_config.user_settings_yaml, null)
        user_settings_override_yaml = try(var.kibana_config.user_settings_override_yaml, null)
      }

      dynamic "topology" {
        for_each = var.kibana_topology

        content {
          size = try(topology.size, null)
          size_resource = try(topology.size_resource, null)
          zone_count = try(topology.zone_count, null)
        }
      }
    }
  }

# /snip

It seems that @mkonopi is also doing the (as far as I know, fairly standard) trick of using a dynamic and for_each with an array of one element to create a single block based on a variable.

My work-around is to just enable Kibana everywhere and hardcode the kibana {} block into the resource, which is obviously less than ideal.

@tobio tobio changed the title Error: The terraform-provider-ec_v0.4.1 plugin crashed! The provider crashes when fields are explicitly set to null Sep 14, 2022
@tobio tobio closed this as completed in #534 Oct 5, 2022
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