Skip to content

Commit

Permalink
refactor: handle error earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Aug 16, 2024
1 parent 45ee5a1 commit 644b676
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,11 +1394,12 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
}

vmState, err := client.GetVmState(vmr)
log.Printf("[DEBUG] VM status: %s", vmState["status"])
if err == nil {
d.Set("vm_state", vmState["status"])
if err != nil {
return diag.FromErr(err)
}
if err == nil && vmState["status"] == "running" {
log.Printf("[DEBUG] VM status: %s", vmState["status"])
d.Set("vm_state", vmState["status"])
if vmState["status"] == "running" {
log.Printf("[DEBUG] VM is running, checking the IP")
// TODO when network interfaces are reimplemented check if we have an interface before getting the connection info
diags = append(diags, initConnInfo(d, client, vmr, config)...)
Expand All @@ -1411,9 +1412,6 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
err = d.Set("ssh_port", nil)
diags = append(diags, diag.FromErr(err)...)
}
if err != nil {
return diag.FromErr(err)
}

logger.Debug().Int("vmid", vmID).Msgf("[READ] Received Config from Proxmox API: %+v", config)

Expand Down

0 comments on commit 644b676

Please sign in to comment.