diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d18d0e8..7807c7ebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ BUG FIXES: * resources/opennebula_virtual_machine: fix `cpumodel` update (#463) * resources/opennebula_service_template: improve `service_template` idempotency (#468) +* resources/opennebula_service: fix service crashes (#469) # 1.3.1 (September 11st, 2023) diff --git a/opennebula/resource_opennebula_service.go b/opennebula/resource_opennebula_service.go index f0a7a6035..b1dca2559 100644 --- a/opennebula/resource_opennebula_service.go +++ b/opennebula/resource_opennebula_service.go @@ -314,7 +314,17 @@ func resourceOpennebulaServiceRead(ctx context.Context, d *schema.ResourceData, var networks = make(map[string]int) for _, val := range sv.Template.Body.NetworksVals { for k, v := range val { - networks[k] = int(v.(map[string]interface{})["id"].(float64)) + s := v.(map[string]interface{})["id"].(string) + networkID, err := strconv.ParseUint(s, 10, 0) + if err != nil { + diags = append(diags, diag.Diagnostic{ + Severity: diag.Error, + Summary: "Failed to parse network ID", + Detail: fmt.Sprintf("service (ID: %s): %s", d.Id(), err), + }) + return diags + } + networks[k] = int(networkID) } } d.Set("networks", networks) @@ -379,10 +389,8 @@ func resourceOpennebulaServiceDelete(ctx context.Context, d *schema.ResourceData Summary: "Failed to recover", Detail: fmt.Sprintf("service (ID: %s): %s", d.Id(), err), }) + return diags } - - return diags - } timeout := d.Timeout(schema.TimeoutDelete)