vexxhost / terraform-provider-uptimerobot

A terraform provider for UptimeRobot
Mozilla Public License 2.0
30 stars 16 forks source link

interface conversion: interface {} is nil, not string #23

Open FlxPeters opened 2 years ago

FlxPeters commented 2 years ago

When running the plugin with Terraform 1.2 I get an interface conversion error. Code was transferred from louy/uptimerobot and provider replaced like documented in the README.

terraform version 
Terraform v1.2.1
on linux_amd64
+ provider registry.terraform.io/vexxhost/uptimerobot v0.8.2

The following stack trace is generated on plan and on apply.

Stack trace from the terraform-provider-uptimerobot_v0.8.2 plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 210 [running]:
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api.UptimeRobotApiClient.GetMonitor({{_, _}}, _)
        github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api/monitor.go:152 +0x1125
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider.resourceMonitorRead(0xc000012980, {0xb66a00, 0xc000235870})
        github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/resource_uptimerobot_monitor.go:192 +0x165
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xb89ee9, {0xc86418, 0xc0004c6080}, 0x24, {0xb66a00, 0xc000235870})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:346 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00029c700, {0xc86418, 0xc0004c6080}, 0xc0006fc1a0, {0xb66a00, 0xc000235870})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:635 +0x35b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc000296768, {0xc86418, 0xc0004c6080}, 0xc0003ac080)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/grpc_provider.go:576 +0x534
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc00028ac80, {0xc864c0, 0xc0004b0000}, 0xc00013a9c0)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:553 +0x3b0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xb613c0, 0xc00028ac80}, {0xc864c0, 0xc0004b0000}, 0xc00013a360, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:344 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002ae700, {0xc93378, 0xc0003a71e0}, 0xc0007b8120, 0xc0003cce40, 0x1133750, 0x0)
        google.golang.org/grpc@v1.43.0/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0002ae700, {0xc93378, 0xc0003a71e0}, 0xc0007b8120, 0x0)
        google.golang.org/grpc@v1.43.0/server.go:1616 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.43.0/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.43.0/server.go:919 +0x294

Error: The terraform-provider-uptimerobot_v0.8.2 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.
FlxPeters commented 2 years ago

I could fix the issue by removing the resources from state and re-import them. Terraform gives me a change for:

  ~ resource "my_monitor" "http" {
      + http_method         = "GET" 

After re-import everything works as expected.

vertis commented 1 year ago

This fails for me as well, without migrating from the old provider

uptimerobot_monitor.platform_production: Creating...
╷
│ Error: Plugin did not respond
│
│   with uptimerobot_monitor.platform_production,
│   on main.tf line 50, in resource "uptimerobot_monitor" "platform_production":
│   50: resource "uptimerobot_monitor" "platform_production" {
│
│ 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-uptimerobot_v0.8.0 plugin:

panic: interface conversion: interface {} is nil, not float64

goroutine 25 [running]:
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api.UptimeRobotApiClient.GetMonitor({{0x1400013c2a0, 0x21}}, 0x2f594d12)
    github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api/monitor.go:156 +0x14d4
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api.UptimeRobotApiClient.CreateMonitor({{0x1400013c2a0, 0x21}}, {{0x1400028e0d8, 0x13}, {0x1400028e108, 0x16}, {0x14000282284, 0x4}, 0x12c, {0x0, ...}, ...})
    github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api/monitor.go:278 +0x1a78
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider.resourceMonitorCreate(0x14000295300, {0x100ba9420, 0x14000284280})
    github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/resource_uptimerobot_monitor.go:175 +0x7bc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x1400009a700, {0x100be76b8, 0x1400028a4c0}, 0x14000295300, {0x100ba9420, 0x14000284280})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:329 +0x170
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x1400009a700, {0x100be76b8, 0x1400028a4c0}, 0x14000438820, 0x14000295180, {0x100ba9420, 0x14000284280})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:467 +0x8d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x1400000c780, {0x100be76b8, 0x1400028a4c0}, 0x14000430640)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/grpc_provider.go:977 +0xe38
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140000bcb80, {0x100be7760, 0x14000094210}, 0x140004c9c00)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:603 +0x338
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100ba39c0, 0x140000bcb80}, {0x100be7760, 0x14000094210}, 0x14000138720, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140000ac700, {0x100bf2f58, 0x14000400680}, 0x140004bc240, 0x14000396d50, 0x10106a7a0, 0x0)
    google.golang.org/grpc@v1.43.0/server.go:1282 +0xc60
google.golang.org/grpc.(*Server).handleStream(0x140000ac700, {0x100bf2f58, 0x14000400680}, 0x140004bc240, 0x0)
    google.golang.org/grpc@v1.43.0/server.go:1616 +0xa34
google.golang.org/grpc.(*Server).serveStreams.func1.2(0x1400042a520, 0x140000ac700, {0x100bf2f58, 0x14000400680}, 0x140004bc240)
    google.golang.org/grpc@v1.43.0/server.go:921 +0x94
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.43.0/server.go:919 +0x1f0

Error: The terraform-provider-uptimerobot_v0.8.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.

Fairly minimal setup:

variable "uptimerobot_api_key" {
  type = string
  description = "Uptime Robot API Key"
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
    uptimerobot = {
      source = "vexxhost/uptimerobot"
      version = "0.8.0"
    }
  }
}

provider "uptimerobot" {
  api_key = "${var.uptimerobot_api_key}"
}

data "uptimerobot_account" "account" {}

# data "uptimerobot_alert_contact" "default_alert_contact" {
#   friendly_name = data.uptimerobot_account.account.email
#   value        = data.uptimerobot_account.account.email
# }

# resource "uptimerobot_alert_contact" "slack" {
#   friendly_name = "Slack Alert"
#   type          = "slack"
#   value         = "https://hooks.slack.com/services/XXXXXXX"
# }

# Create a monitor
resource "uptimerobot_monitor" "platform_production" {
  friendly_name = "Platform Production"
  type          = "http"
  url           = "https://partmax.com.au"
  interval      = 300
#   alert_contact {
#     id = data.uptimerobot_alert_contact.default_alert_contact.id
#   }
}

And a newly created FREE uptimerobot account (I'm planning to upgrade, but first things first).

vertis commented 1 year ago

If I use 0.8.2 instead of 0.8.0 which is linked from the readme then this is fixed.

Might be worth merging:

https://github.com/vexxhost/terraform-provider-uptimerobot/pull/19