Skip to content
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

Fix: nil pointer check for instance #172

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions civo/datasource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,23 @@ func dataSourceInstanceRead(_ context.Context, d *schema.ResourceData, m interfa
log.Printf("[INFO] Getting the instance by id")
image, err := apiClient.FindInstance(id.(string))
if err != nil {
return diag.Errorf("[ERR] failed to retrive instance: %s", err)
return diag.Errorf("[ERR] failed to retrieve instance: %s", err)
}

foundImage = image
} else if hostname, ok := d.GetOk("hostname"); ok {
log.Printf("[INFO] Getting the instance by hostname")
image, err := apiClient.FindInstance(hostname.(string))
if err != nil {
return diag.Errorf("[ERR] failed to retrive instance: %s", err)
return diag.Errorf("[ERR] failed to retrieve instance: %s", err)
}

foundImage = image
}

//Check for nil pointer
if foundImage == nil {
return diag.Errorf("[ERR] failed to retrieve instance, image not found")
}
d.SetId(foundImage.ID)
d.Set("hostname", foundImage.Hostname)
d.Set("reverse_dns", foundImage.ReverseDNS)
Expand Down