spacelift-io / terraform-provider-spacelift

Terraform provider to interact with Spacelift
MIT License
74 stars 28 forks source link

Provider crashes with "Error: Plugin did not respond" #340

Closed kmcquade closed 2 years ago

kmcquade commented 2 years ago

I'm getting a puzzling crash message. See below.

Some context:

[01G9J6XDP5B1XFGQGXA5W85GGK] Running 0 custom hooks...
[01G9J6XDP5B1XFGQGXA5W85GGK] Applying changes...
module.test_stack.spacelift_stack.this: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with spacelift_policy.dev_apply_policy,
│   on policies.tf line 4, in resource "spacelift_policy" "dev_apply_policy":
│    4: resource "spacelift_policy" "dev_apply_policy" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with spacelift_policy.test_apply_policy,
│   on policies.tf line 10, in resource "spacelift_policy" "test_apply_policy":
│   10: resource "spacelift_policy" "test_apply_policy" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with spacelift_policy.staging_apply_policy,
│   on policies.tf line 16, in resource "spacelift_policy" "staging_apply_policy":
│   16: resource "spacelift_policy" "staging_apply_policy" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with spacelift_policy.prod_apply_policy,
│   on policies.tf line 22, in resource "spacelift_policy" "prod_apply_policy":
│   22: resource "spacelift_policy" "prod_apply_policy" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.customer_stack_acme.spacelift_stack.this,
│   on .terraform/modules/customer_stack_acme/main.tf line 1, in resource "spacelift_stack" "this":
│    1: resource "spacelift_stack" "this" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.dev_stack.spacelift_stack.this,
│   on .terraform/modules/dev_stack/main.tf line 1, in resource "spacelift_stack" "this":
│    1: resource "spacelift_stack" "this" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.prod_stack.spacelift_stack.this,
│   on .terraform/modules/prod_stack/main.tf line 1, in resource "spacelift_stack" "this":
│    1: resource "spacelift_stack" "this" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.staging_stack.spacelift_stack.this,
│   on .terraform/modules/staging_stack/main.tf line 1, in resource "spacelift_stack" "this":
│    1: resource "spacelift_stack" "this" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.test_stack.spacelift_stack.this,
│   on .terraform/modules/test_stack/main.tf line 1, in resource "spacelift_stack" "this":
│    1: resource "spacelift_stack" "this" {
│ 
│ 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-spacelift_v0.1.22 plugin:

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

goroutine 66 [running]:
github.com/spacelift-io/terraform-provider-spacelift/spacelift.stackInput(_)
    github.com/spacelift-io/terraform-provider-spacelift/spacelift/resource_stack.go:708 +0x1e05
github.com/spacelift-io/terraform-provider-spacelift/spacelift.resourceStackCreate({0xd8f708, 0xc00007ac60}, 0xb81ca0?, {0xbcb420?, 0xc0003b8ba0?})
    github.com/spacelift-io/terraform-provider-spacelift/spacelift/resource_stack.go:413 +0xc5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0002fb0a0, {0xd8f740, 0xc000581770}, 0xd?, {0xbcb420, 0xc0003b8ba0})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0002fb0a0, {0xd8f740, 0xc000581770}, 0xc000596f70, 0xc000158c80, {0xbcb420, 0xc0003b8ba0})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/resource.go:837 +0xa7a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0002c4558, {0xd8f698?, 0xc000422f40?}, 0xc000572870)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002a4640, {0xd8f740?, 0xc000580d50?}, 0xc0003f61c0)
    github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/tf5server/server.go:812 +0x515
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xc34aa0?, 0xc0002a4640}, {0xd8f740, 0xc000580d50}, 0xc00007a4e0, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00017ca80, {0xd92130, 0xc0000031e0}, 0xc00057f440, 0xc0003062d0, 0x122b100, 0x0)
    google.golang.org/grpc@v1.45.0/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc00017ca80, {0xd92130, 0xc0000031e0}, 0xc00057f440, 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-spacelift_v0.1.22 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.

[01G9J6XDP5B1XFGQGXA5W85GGK] Unexpected exit code when applying changes: 1
[01G9J6XDP5B1XFGQGXA5W85GGK] Uploading the list of managed resources...
[01G9J6XDP5B1XFGQGXA5W85GGK] Resource list upload is GO
kmcquade commented 2 years ago

I tried changing the provider version to 0.1.21 and it still failed

image

marcinwyszynski commented 2 years ago

I believe it's an HCL bug that we need to work around:

resource "spacelift_stack" "this" {
  branch            = "master"
  name              = "Repro for 340"
  repository        = "empty"

  github_enterprise {
    namespace = "" # <- this line causes the crash
  }
}

HCL doesn't see the difference between an empty string and a "null", and treats the entire block as nil rather than map[string]interface{}{"github_enterprise": ""} as I would expect. That breaks the interface conversion.