From 3572815c3b3aa2d08960309c34e1f5b80b90e67a Mon Sep 17 00:00:00 2001 From: Mateus Caruccio Date: Tue, 15 Dec 2020 12:08:51 -0300 Subject: [PATCH] Resolves #79 --- internal/provider/data_source_tls_certificate.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/provider/data_source_tls_certificate.go b/internal/provider/data_source_tls_certificate.go index baf081cf..96752f0b 100644 --- a/internal/provider/data_source_tls_certificate.go +++ b/internal/provider/data_source_tls_certificate.go @@ -96,9 +96,17 @@ func dataSourceTlsCertificateRead(d *schema.ResourceData, _ interface{}) error { defer conn.Close() state := conn.ConnectionState() + var sha1_fingerprint string var certs []interface{} for i := len(state.PeerCertificates) - 1; i >= 0; i-- { certs = append(certs, parsePeerCertificate(state.PeerCertificates[i])) + sfp := certs[i].(struct{ sha1_fingerprint string }).sha1_fingerprint + if i == 0 { + sha1_fingerprint = sfp + } else { + sha1_fingerprint = sfp + certs[i-1].(struct{ sha1_fingerprint string }).sha1_fingerprint + sha1_fingerprint = fmt.Sprintf("%x", sha1.Sum([]byte(sha1_fingerprint))) + } } err = d.Set("certificates", certs) @@ -106,7 +114,7 @@ func dataSourceTlsCertificateRead(d *schema.ResourceData, _ interface{}) error { return err } - d.SetId(time.Now().UTC().String()) + d.SetId(sha1_fingerprint) return nil }