Skip to content

Plugin crashes for monitor with invalid request_headers #151

@NerdyMcNerd

Description

@NerdyMcNerd

When a monitor resource has an empty map in the request_headers list, the provider plugin crashes.

Example code:

resource "betteruptime_monitor" "test" {
  monitor_type       = "status"
  url                = "https://www.wikipedia.org/"
  pronounceable_name = "Test monitor"
  paused             = true

  request_headers = [
    {}, # <---- this is the offending value
    {
      name  = "Valid-Header"
      value = "Valid-Value"
    }
  ]
}

the minimal value triggering the crash is: request_headers = [{}]

The error shown is:

Stack trace from the terraform-provider-better-uptime_v0.19.0.exe plugin:

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

  goroutine 82 [running]:
  github.com/BetterStackHQ/terraform-provider-better-uptime/internal/provider.loadRequestHeaders(0xc000692e00, 0xc000208240)
        github.com/BetterStackHQ/terraform-provider-better-uptime/internal/provider/resource_monitor.go:640 +0xb97
  github.com/BetterStackHQ/terraform-provider-better-uptime/internal/provider.monitorCreate({0x12277c8, 0xc0001e9110}, 0xc000692e00, {0x102ac60, 0xc00013c300})
        github.com/BetterStackHQ/terraform-provider-better-uptime/internal/provider/resource_monitor.go:534 +0xf4
  github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000331100, {0x1227720, 0xc00037cf00}, 0xc000692e00, {0x102ac60, 0xc00013c300})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:838 +0x119
  github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000331100, {0x1227720, 0xc00037cf00}, 0xc000691ba0, 0xc000692b00, {0x102ac60, 0xc00013c300})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:969 +0xa69
  github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00040c5a0, {0x1227720?, 0xc00037ce40?}, 0xc0001ad3b0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1188 +0xd5c
  github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002ff5e0, {0x1227720?, 0xc00037c390?}, 0xc0001e8af0)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:866 +0x3bc
  github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x10c0780, 0xc0002ff5e0}, {0x1227720, 0xc00037c390}, 0xc000692280, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:611 +0x1a6
  google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002b2200, {0x1227720, 0xc00037c330}, 0xc0000b2360, 0xc00037de90, 0x17d9878, 0x0)     
        google.golang.org/[email protected]/server.go:1392 +0xfc3
  google.golang.org/grpc.(*Server).handleStream(0xc0002b2200, {0x1227f28, 0xc000502000}, 0xc0000b2360)
        google.golang.org/[email protected]/server.go:1802 +0xbaa
  google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/[email protected]/server.go:1030 +0x7f
  created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 21
        google.golang.org/[email protected]/server.go:1041 +0x125

  Error: The terraform-provider-better-uptime_v0.19.0.exe 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.


  exit status 1

Even though this is clearly the wrong value, I think it would be better if this was caught during validation and result in a meaningful error message instead of a crash with a golang stack trace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions