From 19a55d2875ba015bfb6aa160e1589cdbebb486a9 Mon Sep 17 00:00:00 2001 From: dgupta Date: Wed, 28 Feb 2024 19:45:54 +0530 Subject: [PATCH] Added godo changes for fetching certificate by name --- .../certificate/datasource_certificate.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/digitalocean/certificate/datasource_certificate.go b/digitalocean/certificate/datasource_certificate.go index 163e323e1..a4732c2e4 100644 --- a/digitalocean/certificate/datasource_certificate.go +++ b/digitalocean/certificate/datasource_certificate.go @@ -93,23 +93,14 @@ func dataSourceDigitalOceanCertificateRead(ctx context.Context, d *schema.Resour } func FindCertificateByName(client *godo.Client, name string) (*godo.Certificate, error) { - opts := &godo.ListOptions{ - Name: name, - } - certs, resp, err := client.Certificates.List(context.Background(), opts) + 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) } - - for _, cert := range certs { - if cert.Name == name { - return &cert, nil - } - } - - return nil, fmt.Errorf("Certificate %s not found", name) + return cert, err }