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

Plugin Crash - runtime error - out of range #487

Closed RedRaikiri closed 9 months ago

RedRaikiri commented 9 months ago

Dear community, dear developers,

I am trying to import my existing Postgres-DB-Sever into its own module. All my other components are processed correctly but in this case the plugin crashes. I hope I just made a stupid mistake. Help would be awesome. Thank you in advance!

The code:

resource "ionoscloud_server" "Postgres-Datenbank"{ name = "Postgres-Datenbank" datacenter_id = var.ionosDatacenterID image_password = cores = 2 ram = 4096 cpu_family = "INTEL_SKYLAKE" vm_state = "SHUTOFF" volume { name = "Postgres-Storage" disk_type = "HDD" size = 12 } }

Import in import.tf:

import { id = "" to = module.PostgreSQL_Database.ionoscloud_server.Postgres-Datenbank }

Here are the relevant parts of the Error Log:

╷ │ Error: Plugin did not respond │ │ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ImportResourceState call. The plugin logs may contain more details. ╵

Error: Plugin did not respond │ │ with module.basicAccessJumphost.ionoscloud_cube_server.Jumphost, │ on modules\services\basicAccessJumphost\jumphost.tf line 10, in resource "ionoscloud_cube_server" "Jumphost": │ 10: resource "ionoscloud_cube_server" "Jumphost" { │ │ 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_v6.4.10.exe plugin:

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

goroutine 65 [running]: github.com/ionos-cloud/terraform-provider-ionoscloud/v6/ionoscloud.resourceServerImport({0x1a7c8ec, 0xaf841c8}, 0xaf18be0, {0x18634e0, 0xafc2c80}) github.com/ionos-cloud/terraform-provider-ionoscloud/v6/ionoscloud/resource_server.go:1275 +0xd67 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(Provider).ImportState(0xac6a660, {0x1a7c8ec, 0xaf841c8}, 0xac63af0, {0xaf0e960, 0x49}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/provider.go:388 +0x1cd github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(GRPCProviderServer).ImportResourceState(0xaf10ed0, {0x1a7c8ec, 0xaf84168}, 0xb103a80) github.com/hashicorp/terraform-plugin-sdk/v2@v2.28.0/helper/schema/grpc_provider.go:1097 +0xce github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(server).ImportResourceState(0xaf185a0, {0x1a7c8ec, 0xadbde18}, 0xaddfe00) github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:851 +0x22e github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ImportResourceState_Handler({0x18a3bc0, 0xaf185a0}, {0x1a7c8ec, 0xadbde18}, 0xae2fb00, 0x0) github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:440 +0x18a google.golang.org/grpc.(Server).processUnaryRPC(0xaf12120, {0x1a7e460, 0xacc0c60}, 0xb0fa0a0, 0xae83470, 0x22112cc, 0x0) google.golang.org/grpc@v1.56.1/server.go:1337 +0xeba google.golang.org/grpc.(Server).handleStream(0xaf12120, {0x1a7e460, 0xacc0c60}, 0xb0fa0a0, 0x0) google.golang.org/grpc@v1.56.1/server.go:1714 +0xa1e google.golang.org/grpc.(Server).serveStreams.func1.1() google.golang.org/grpc@v1.56.1/server.go:959 +0xb1 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.56.1/server.go:957 +0x178

Error: The terraform-provider-ionoscloud_v6.4.10.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.


Linked the first error in Blame, to find it faster:

https://github.com/ionos-cloud/terraform-provider-ionoscloud/blame/e660056234f56add47130cb1d392667500265031/ionoscloud/resource_server.go#L1275

RedRaikiri commented 9 months ago

Realized the following:

if I import with datacenter/server (UUIDs) it results in the error. If I import with datacenter/server/nic (UUIDs) it can fetch the Server information.

A bit confusing, that I can import the server through the nic (sub-component). But fine for me. I think the server itself should be imported with only the server-id and datacenter-id as well. I will keep the issue open.

cristiGuranIonos commented 8 months ago

Fixed in v6.4.11