vexxhost / terraform-provider-uptimerobot

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

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

Closed gtirloni closed 2 years ago

gtirloni commented 2 years ago

I'm trying to convert to this new fork but I'm getting the following error when running terraform plan on the existing resources:

$ TF_LOG=ERROR terraform plan
...
uptimerobot_monitor.my_website_com: Refreshing state... [id=1234567890]
2022-02-08T21:25:18.809-0300 [ERROR] plugin.(*GRPCProvider).ReadResource: error="rpc error: code = Unavailable desc = transport is closing"
2022-02-08T21:25:18.809-0300 [ERROR] plugin.(*GRPCProvider).UpgradeResourceState: error="rpc error: code = Canceled desc = context canceled"

...

│ Error: Request cancelled
│ 
│   with uptimerobot_monitor.mywebsite_com,
│   on monitors.tf line 1, in resource "uptimerobot_monitor" "mywebsite_com":
│    1: resource "uptimerobot_monitor" "mywebsite_com" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
...

Releasing state lock. This may take a few moments...

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

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

goroutine 109 [running]:
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api.UptimeRobotApiClient.GetMonitor({{_, _}}, _)
    github.com/vexxhost/terraform-provider-uptimerobot/internal/provider/api/monitor.go:156 +0x1254
github.com/vexxhost/terraform-provider-uptimerobot/internal/provider.resourceMonitorRead(0xc00042af00, {0xb657c0, 0xc000235aa0})
    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(0xb88c7f, {0xc84f78, 0xc00023f440}, 0x24, {0xb657c0, 0xc000235aa0})
    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(0xc00029e700, {0xc84f78, 0xc00023f440}, 0xc00013ba00, {0xb657c0, 0xc000235aa0})
    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(0xc000284780, {0xc84f78, 0xc00023f440}, 0xc00023f4c0)
    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(0xc000298c00, {0xc85020, 0xc000458e40}, 0xc00007db60)
    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({0xb60180, 0xc000298c00}, {0xc85020, 0xc000458e40}, 0xc00007db00, 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(0xc0002b0700, {0xc91e98, 0xc000230d00}, 0xc000588c60, 0xc0003c6f30, 0x1132750, 0x0)
    google.golang.org/grpc@v1.43.0/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0002b0700, {0xc91e98, 0xc000230d00}, 0xc000588c60, 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.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.

ERRO[0008] 1 error occurred:
    * exit status 1

I've done the provider conversion with terraform state replace-provider and updated the TF definitions to use v0.8.0.

Any help is welcome.

gtirloni commented 2 years ago

Just tested v0.7.0 and it works fine.

caius commented 2 years ago

Ran into the same panic, and downgrading to 0.7.0 worked here as a workaround. Haven't dug into the code changes to try and see why it's occurring yet.

caius commented 2 years ago

I wonder if https://github.com/vexxhost/terraform-provider-uptimerobot/pull/12 will fix it actually, looks to be in related code and checking related behaviour.

mnaser commented 2 years ago

I believe this is closed by #12

iautom8things commented 2 years ago

Hi, new user of UptimeRobot and this module. Thank you for providing it!

I'm not sure if #12 has been included in a release or not, but I've encountered this issue. Setting http_method = "GET" got me further where several of the http checks were created, but ultimately terraform still failed.

I've downgraded to 0.7.0 but now I get the error

╷
│ Error: Monitor not found: 791874630
│
│   with uptimerobot_monitor.production-portal["org1"],
│   on uptime_monitors.tf line 40, in resource "uptimerobot_monitor" "production-portal":
│   40: resource "uptimerobot_monitor" "production-portal" {
│
╵
╷
│ Error: Monitor not found: 791874617
│
│   with uptimerobot_monitor.production-portal["org2"],
│   on uptime_monitors.tf line 40, in resource "uptimerobot_monitor" "production-portal":
│   40: resource "uptimerobot_monitor" "production-portal" {
│
╵

This goes on. But the monitors are actually created 🤷‍♂️

mnaser commented 2 years ago

which version are you using of the module?

iautom8things commented 2 years ago

I was using 0.8.0 but this caused the error originally mentioned in this issue. I then downgraded to 0.7.0 this version created the monitors but returned the errors I showed.

Edit: I see my mistake! It looks like there is a new version, 0.8.2. I'll send a PR to update the readme that I was following.

Thank you, I'll try this version out