From 97feaf94ac81211bb43635f221732c8aaae464d4 Mon Sep 17 00:00:00 2001 From: Jaikanth J Date: Sun, 21 May 2023 20:02:25 +0530 Subject: [PATCH 1/2] feat(timeout): use timeout from plugin SDK --- venafi/resource_venafi_certificate.go | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/venafi/resource_venafi_certificate.go b/venafi/resource_venafi_certificate.go index 7f48c56..52a7b09 100644 --- a/venafi/resource_venafi_certificate.go +++ b/venafi/resource_venafi_certificate.go @@ -10,6 +10,14 @@ import ( "encoding/base64" "encoding/pem" "fmt" + "log" + "math" + "net" + "net/url" + "strconv" + "strings" + "time" + "github.com/Venafi/vcert/v4" "github.com/Venafi/vcert/v4/pkg/certificate" "github.com/Venafi/vcert/v4/pkg/endpoint" @@ -19,14 +27,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/youmark/pkcs8" - "log" - "math" - "net" - "net/url" "software.sslmate.com/src/go-pkcs12" - "strconv" - "strings" - "time" ) const ( @@ -188,6 +189,9 @@ func resourceVenafiCertificate() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: resourceVenafiCertificateImport, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(180 * time.Second), + }, } } @@ -272,7 +276,7 @@ func resourceVenafiCertificateRead(ctx context.Context, d *schema.ResourceData, } origin := d.Get("csr_origin").(string) - pickupReq := fillRetrieveRequest(pickupID, keyPassword, cl.GetType(), origin) + pickupReq := fillRetrieveRequest(pickupID, keyPassword, cl.GetType(), origin, d.Timeout(schema.TimeoutRead)) data, err := cl.RetrieveCertificate(pickupReq) if err != nil { @@ -628,7 +632,7 @@ func enrollVenafiCertificate(ctx context.Context, d *schema.ResourceData, cl end } } - pickupReq := fillRetrieveRequest(requestID, pickupPass, cl.GetType(), origin) + pickupReq := fillRetrieveRequest(requestID, pickupPass, cl.GetType(), origin, d.Timeout(schema.TimeoutCreate)) err = d.Set("certificate_dn", requestID) if err != nil { @@ -813,7 +817,7 @@ func resourceVenafiCertificateImport(ctx context.Context, d *schema.ResourceData pickupID = fmt.Sprintf("%s\\%s", zone, pickupID) } - pickupReq := fillRetrieveRequest(pickupID, keyPassword, cl.GetType(), csrService) + pickupReq := fillRetrieveRequest(pickupID, keyPassword, cl.GetType(), csrService, d.Timeout(schema.TimeoutDefault)) data, err := cl.RetrieveCertificate(pickupReq) if err != nil { @@ -843,9 +847,9 @@ func resourceVenafiCertificateImport(ctx context.Context, d *schema.ResourceData return []*schema.ResourceData{d}, nil } -func fillRetrieveRequest(id string, password string, connectorType endpoint.ConnectorType, origin string) *certificate.Request { +func fillRetrieveRequest(id string, password string, connectorType endpoint.ConnectorType, origin string, timeout time.Duration) *certificate.Request { pickupReq := &certificate.Request{} - pickupReq.Timeout = 180 * time.Second + pickupReq.Timeout = timeout pickupReq.PickupID = id pickupReq.KeyPassword = password From 1fdc4023375eb72c8974c4abf9672b70ca992c84 Mon Sep 17 00:00:00 2001 From: Jaikanth J Date: Sun, 21 May 2023 20:07:55 +0530 Subject: [PATCH 2/2] fix (timeout): make 3 mins as defaults for all to match with previous hardcoded configuration --- venafi/resource_venafi_certificate.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/venafi/resource_venafi_certificate.go b/venafi/resource_venafi_certificate.go index 52a7b09..93c7769 100644 --- a/venafi/resource_venafi_certificate.go +++ b/venafi/resource_venafi_certificate.go @@ -190,7 +190,9 @@ func resourceVenafiCertificate() *schema.Resource { StateContext: resourceVenafiCertificateImport, }, Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(180 * time.Second), + Create: schema.DefaultTimeout(180 * time.Second), + Read: schema.DefaultTimeout(180 * time.Second), + Default: schema.DefaultTimeout(180 * time.Second), }, } }