diff --git a/digitalocean/certificate/datasource_certificate.go b/digitalocean/certificate/datasource_certificate.go index 50ecbf6ff..7362a6021 100644 --- a/digitalocean/certificate/datasource_certificate.go +++ b/digitalocean/certificate/datasource_certificate.go @@ -95,14 +95,14 @@ func dataSourceDigitalOceanCertificateRead(ctx context.Context, d *schema.Resour func FindCertificateByName(client *godo.Client, name string) (*godo.Certificate, error) { cert, resp, err := client.Certificates.ListByName(context.Background(), name, nil) - if resp != nil && resp.StatusCode == http.StatusNotFound { - return nil, nil - } - if err != nil { return nil, fmt.Errorf("Error retrieving certificates: %s", err) } + if resp != nil && resp.StatusCode == http.StatusNotFound { + return nil, nil + } + if len(cert) == 0 { return nil, fmt.Errorf("certificate not found") }