Skip to content

Commit

Permalink
B #469: Fix service crashes
Browse files Browse the repository at this point in the history
- correctly parse network IDs
- correctly handle the "recover --delete" cleanup
  • Loading branch information
sk4zuzu committed Dec 12, 2023
1 parent febb74b commit 0e1f3e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 12 additions & 4 deletions opennebula/resource_opennebula_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.ParseUint
to a lower bit size type int without an upper bound check.
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.ParseUint
to a lower bit size type int without an upper bound check.
}
}
d.Set("networks", networks)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0e1f3e1

Please sign in to comment.