ionos-cloud / terraform-provider-ionoscloud

The IonosCloud Terraform provider gives the ability to deploy and configure resources using the IonosCloud APIs.
Mozilla Public License 2.0
34 stars 23 forks source link

Crash when importing: invalid memory address or nil pointer dereference #5

Closed larsen0815 closed 3 years ago

larsen0815 commented 3 years ago

Description

I used this command (which probably isn't correct) and the plugin crashed terraform import ionoscloud_server.${name_server} ${ID_DC}/${ID_SERVER}/33b25c25-7e79-4b8b-8f91-2a64692578d1 Seems like it cannot handle a UID as a NIC.

Expected behavior

Should return something like "Proper value range is from 1 to 99".

Environment

Terraform version:

Terraform v0.15.3
on linux_amd64

Provider version:

provider registry.terraform.io/ionos-cloud/ionoscloud v5.0.4

OS:

Debian Buster

Error and Debug Output

ionoscloud_server.texas: Importing from ID "6cf8015a-3bba-447b-8e94-4c260cf3b0ac/fcb80aee-be10-4012-83a2-2b4259f46e08/33b25c25-7e79-4b8b-8f91-2a64692578d1"...
ionoscloud_server.texas: Import prepared!
  Prepared ionoscloud_server for import
ionoscloud_server.texas: Refreshing state... [id=fcb80aee-be10-4012-83a2-2b4259f46e08]
?
¦ Error: Plugin did not respond
¦
¦ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
?

Stack trace from the terraform-provider-ionoscloud_v5.0.4 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xedd425]

goroutine 27 [running]:
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.resourceServerRead(0xc000544850, 0x117b140, 0xc0004acfc0, 0xc000544850, 0x0)
    github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/resource_server.go:748 +0xb55
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000418bd0, 0xc000074eb0, 0x117b140, 0xc0004acfc0, 0xc00000f480, 0x0, 0x0)
    github.com/hashicorp/terraform-plugin-sdk@v1.14.0/helper/schema/resource.go:460 +0x119
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000f530, 0x146f000, 0xc000549560, 0xc00054e2a0, 0xc00000f530, 0xc000549560, 0xc0001b4ba0)
    github.com/hashicorp/terraform-plugin-sdk@v1.14.0/internal/helper/plugin/grpc_provider.go:525 +0x3d8
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x113be80, 0xc00000f530, 0x146f000, 0xc000549560, 0xc00054e1e0, 0x0, 0x146f000, 0xc000549560, 0xc0000d4c80, 0x242)
    github.com/hashicorp/terraform-plugin-sdk@v1.14.0/internal/tfplugin5/tfplugin5.pb.go:3269 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000554000, 0x147ba60, 0xc00018f200, 0xc0001e8200, 0xc00010a3f0, 0x1c5fcd0, 0x0, 0x0, 0x0)
    google.golang.org/grpc@v1.30.0/server.go:1171 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc000554000, 0x147ba60, 0xc00018f200, 0xc0001e8200, 0x0)
    google.golang.org/grpc@v1.30.0/server.go:1494 +0xccd
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000034570, 0xc000554000, 0x147ba60, 0xc00018f200, 0xc0001e8200)
    google.golang.org/grpc@v1.30.0/server.go:834 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.30.0/server.go:832 +0x204

Error: The terraform-provider-ionoscloud_v5.0.4 plugin crashed!
larsen0815 commented 3 years ago

Still crashes with terraform 1.0.0

larsen0815 commented 3 years ago

Updated the provider to 5.1.3, now another crash happens if I use "endpoint" (which used to work in 5.0.4):

provider "ionoscloud" {
  username = "none@example.com"
  password = "xxx"
  endpoint = "https://nbc-api.nexinto.com/cloudapi/v6"
}
?
¦ Error: Plugin did not respond
¦
¦   with provider["registry.terraform.io/ionos-cloud/ionoscloud"],
¦   on /root/terraform/demo/test.tf line 9, in provider "ionoscloud":
¦    9: provider "ionoscloud" {
¦
¦ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain more details.
?

Stack trace from the terraform-provider-ionoscloud_v5.1.3 plugin:

panic: runtime error: index out of range [2] with length 2

goroutine 25 [running]:
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.providerConfigure(0xc0002cc2a0, 0xc0002b53b0, 0x5, 0x1, 0x1, 0xebfd78, 0x1508140)
    github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/provider.go:137 +0x752
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.Provider.func1(0xc0002cc2a0, 0x0, 0xc000803120, 0xc0002cc2a0, 0x0)
    github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/provider.go:102 +0xd1
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Configure(0xc0000b9780, 0xc0002bbc20, 0x137b820, 0xc0002bbb90)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/helper/schema/provider.go:275 +0xf6
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).Configure(0xc00000f760, 0x18d0ea0, 0xc0002bb6b0, 0xc000521200, 0xc00000f760, 0xc0002bb6b0, 0xc00015dba0)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/helper/plugin/grpc_provider.go:487 +0x2e6
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_Configure_Handler(0x14f1c40, 0xc00000f760, 0x18d0ea0, 0xc0002bb6b0, 0xc0002af4a0, 0x0, 0x18d0ea0, 0xc0002bb6b0, 0xc000112320, 0x9c)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/tfplugin5/tfplugin5.pb.go:3251 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00017ddc0, 0x18df9a0, 0xc00059d380, 0xc0001cec00, 0xc0000fe630, 0x22c3358, 0x0, 0x0, 0x0)
    google.golang.org/grpc@v1.31.1/server.go:1180 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc00017ddc0, 0x18df9a0, 0xc00059d380, 0xc0001cec00, 0x0)
    google.golang.org/grpc@v1.31.1/server.go:1503 +0xcfd
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0000340a0, 0xc00017ddc0, 0x18df9a0, 0xc00059d380, 0xc0001cec00)
    google.golang.org/grpc@v1.31.1/server.go:843 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.31.1/server.go:841 +0x204

Error: The terraform-provider-ionoscloud_v5.1.3 plugin crashed!
benschmi commented 3 years ago

The panic in regards to the endpoint parameter is already documented in #12 . This seems to be a duplicate. Can we close the original issue in regards to panic when importing since this seems to be fixed?

larsen0815 commented 3 years ago

Yes. The first problem I noticed seems to have been fixed in the meantime. I hadn't seen the other issue when I updated this ticket with the crash from the new version.

benschmi commented 3 years ago

Thank you :)

larsen0815 commented 3 years ago

I'm afraid the initial crash had only been masked by the second one. After updating the provider to 5.1.5 it's back.

Stack trace from the terraform-provider-ionoscloud_v5.1.5 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11fb7e1]

goroutine 27 [running]:
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.resourceServerRead(0xc0002d6af0, 0x145b460, 0xc0002d10e0, 0x0, 0x0)
    github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/resource_server.go:829 +0xc21
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000438a20, 0xc0002dad20, 0x145b460, 0xc0002d10e0, 0xc0002868e8, 0x0, 0x0)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/helper/schema/resource.go:460 +0x119
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc00000f768, 0x18de3a0, 0xc000317950, 0xc0002bf5c0, 0xc00000f768, 0xc000317950, 0xc0005eeba0)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/helper/plugin/grpc_provider.go:525 +0x3d8
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x14fcc80, 0xc00000f768, 0x18de3a0, 0xc000317950, 0xc0002bf560, 0x0, 0x18de3a0, 0xc000317950, 0xc0005e3180, 0x242)
    github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/tfplugin5/tfplugin5.pb.go:3269 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00017ddc0, 0x18ece40, 0xc00059b080, 0xc0001cce00, 0xc000100690, 0x22cf370, 0x0, 0x0, 0x0)
    google.golang.org/grpc@v1.31.1/server.go:1180 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc00017ddc0, 0x18ece40, 0xc00059b080, 0xc0001cce00, 0x0)
    google.golang.org/grpc@v1.31.1/server.go:1503 +0xcfd
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000034550, 0xc00017ddc0, 0x18ece40, 0xc00059b080, 0xc0001cce00)
    google.golang.org/grpc@v1.31.1/server.go:843 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.31.1/server.go:841 +0x204
maboehm commented 3 years ago

@larsen0815 I had a similar crash, and maybe for a similar reason. For me it crashed setting the kubeconfig on an imported kubernetes cluster.

Above you mentioned your endpoint is endpoint = "https://nbc-api.nexinto.com/cloudapi/v6", which is incompatible with this terraform provider, since it uses https://github.com/ionos-cloud/sdk-go, which is built using the v5 swagger definition.

For me switching from the V6 to the V5 endpoint fixed the crash

mflorin commented 3 years ago

@m2hofi94 @larsen0815 - I've just released v5.1.6 which should fix this crash - let me know if it works for you.

larsen0815 commented 3 years ago

Fixed. Thanks a lot for the quick help!