-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed type assertion panic in network ID retrieval #532
Conversation
Refactored network ID retrieval logic to include checks for nil values and to ensure that the 'id' field is of type float64 before conversion. This prevents a panic caused by improper type assertion and ensures robust error handling in case of missing or invalid network IDs.
This pull request is stale because it has been open for 30 days with no activity and it is not in a milestone. Remove 'status: stale' label or comment, or this will be closed in 5 days. |
Reopen plz:
|
The problem seems to be related to the PR #509 Looking at OpenNebula documentation the schema is not clear on the type inside of networks_values An other page in the doc show the id value as a string: The type is not so easy to track, the code from Goca seems to unmarshal/marshal the datas several times Don't hesitate to provide more context in a issue @shurkys (linking some documentation, adding some acceptance test, how to reproduce easily, CHANGELOG informations...), this would help to understand and fix the code more quickly |
This pull request is stale because it has been open for 30 days with no activity and it is not in a milestone. Remove 'status: stale' label or comment, or this will be closed in 5 days. |
variable "opennebula_endpoint" {
default = "http://192.168.1.5:2633/RPC2"
}
variable "opennebula_flow_endpoint" {
default = "http://192.168.1.5:2474"
}
variable "opennebula_username" {
default = "oneadmin"
}
variable "opennebula_password" {
default = "oneadmin"
}
terraform {
required_providers {
opennebula = {
source = "OpenNebula/opennebula"
version = "1.4.0"
}
}
}
provider "opennebula" {
endpoint = var.opennebula_endpoint
flow_endpoint = var.opennebula_flow_endpoint
username = var.opennebula_username
password = var.opennebula_password
}
resource "opennebula_template" "test" {
name = "test"
description = "VM template for test"
cpu = 1
vcpu = 1
memory = 1024
disk {
image_id = 11
}
}
data "opennebula_virtual_network" "test" {
name = "mi_br0" // name of real network
}
resource "opennebula_service_template" "test" {
template = jsonencode(
{
TEMPLATE = {
BODY = {
deployment = "straight"
description = "Test1"
name = "dev"
networks = {
test1 = "M|network|test1| |reserve_from:${data.opennebula_virtual_network.test.id}:SIZE=3"
}
roles = [
{
cardinality = 1
cooldown = 5
max_vms = 3
min_vms = 1
name = "test1"
shutdown_action = "terminate-hard"
vm_template = tonumber(resource.opennebula_template.test.id)
vm_template_contents = <<-EOT
NIC = [
NAME = "_NIC0",
NETWORK_ID = "$test1" ]
EOT
}
]
}
}
}
)
uid = 0
uname = "oneadmin"
}
resource "opennebula_service" "test" {
name = "test" // whatever
template_id = resource.opennebula_service_template.test.id
extra_template = jsonencode(
{
"custom_attrs_values" : {
},
"networks_values" : [{
"test1" : {
"reserve_from" : data.opennebula_virtual_network.test.id,
"extra" : "NAME=Test1\nSIZE=3"
}
}]
}
)
} Apply terraform apply
data.opennebula_virtual_network.test: Reading...
data.opennebula_virtual_network.test: Read complete after 0s [name=mi_br0]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# opennebula_service.test will be created
+ resource "opennebula_service" "test" {
+ extra_template = jsonencode(
{
+ custom_attrs_values = {}
+ networks_values = [
+ {
+ test1 = {
+ extra = <<-EOT
NAME=Test1
SIZE=3
EOT
+ reserve_from = 0
}
},
]
}
)
+ gid = (known after apply)
+ gname = (known after apply)
+ id = (known after apply)
+ name = "test"
+ networks = (known after apply)
+ permissions = (known after apply)
+ roles = (known after apply)
+ state = (known after apply)
+ template_id = (known after apply)
+ uid = (known after apply)
+ uname = (known after apply)
}
# opennebula_service_template.test will be created
+ resource "opennebula_service_template" "test" {
+ gid = (known after apply)
+ gname = (known after apply)
+ id = (known after apply)
+ name = (known after apply)
+ permissions = (known after apply)
+ template = (known after apply)
+ uid = 0
+ uname = "oneadmin"
}
# opennebula_template.test will be created
+ resource "opennebula_template" "test" {
+ cpu = 1
+ default_tags = (known after apply)
+ description = "VM template for test"
+ gid = (known after apply)
+ gname = (known after apply)
+ id = (known after apply)
+ memory = 1024
+ name = "test"
+ permissions = (known after apply)
+ reg_time = (known after apply)
+ tags_all = (known after apply)
+ uid = (known after apply)
+ uname = (known after apply)
+ vcpu = 1
+ disk {
+ image_id = 11
}
+ vmgroup (known after apply)
}
Plan: 3 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
opennebula_template.test: Creating...
opennebula_template.test: Creation complete after 1s [id=30]
opennebula_service_template.test: Creating...
opennebula_service_template.test: Creation complete after 1s [id=101]
opennebula_service.test: Creating...
opennebula_service.test: Still creating... [10s elapsed]
╷
│ Error: Plugin did not respond
│
│ with opennebula_service.test,
│ on main.tf line 83, in resource "opennebula_service" "test":
│ 83: resource "opennebula_service" "test" {
│
│ 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-opennebula_v1.4.0 plugin:
panic: interface conversion: interface {} is float64, not string
goroutine 84 [running]:
github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaServiceRead({0xa1f7c8?, 0x40000b9740?}, 0x4000550c80, {0x7d1700?, 0x40001c9f00?})
github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_service.go:317 +0xe74
github.com/OpenNebula/terraform-provider-opennebula/opennebula.resourceOpennebulaServiceCreate({0xa1f7c8, 0x40000b9740}, 0x4000550c80, {0x7d1700?, 0x40001c9f00})
github.com/OpenNebula/terraform-provider-opennebula/opennebula/resource_opennebula_service.go:258 +0xdc4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x4000314d20, {0xa1f800, 0x4000219110}, 0xd?, {0x7d1700, 0x40001c9f00})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:707 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x4000314d20, {0xa1f800, 0x4000219110}, 0x400059c820, 0x4000550a00, {0x7d1700, 0x40001c9f00})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:837 +0x84c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x400000d788, {0xa1f800?, 0x4000218ff0?}, 0x40004d6230)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xbd0
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x40002f70e0, {0xa1f800?, 0x40002189c0?}, 0x40001d2310)
github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/tf5server/server.go:818 +0x3c4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x897b40?, 0x40002f70e0}, {0xa1f800, 0x40002189c0}, 0x40001d2000, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x400031a1e0, {0xa22a80, 0x4000254000}, 0x4000000c60, 0x400042ab40, 0xf23820, 0x0)
google.golang.org/grpc@v1.56.3/server.go:1335 +0xc68
google.golang.org/grpc.(*Server).handleStream(0x400031a1e0, {0xa22a80, 0x4000254000}, 0x4000000c60, 0x0)
google.golang.org/grpc@v1.56.3/server.go:1712 +0x854
google.golang.org/grpc.(*Server).serveStreams.func1.1()
google.golang.org/grpc@v1.56.3/server.go:947 +0xb4
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/grpc@v1.56.3/server.go:958 +0x184
Error: The terraform-provider-opennebula_v1.4.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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this + LGTM.
Refactored network ID retrieval logic to include checks for nil values and to ensure that the 'id' field is of type float64 before conversion. This prevents a panic caused by improper type assertion and ensures robust error handling in case of missing or invalid network IDs.
Community Note
Description
References
#000
New or Affected Resource(s)
Checklist
References
go fmt
)