diff --git a/venafi/resource_venafi_certificate.go b/venafi/resource_venafi_certificate.go index 7f48c56..93c7769 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,11 @@ func resourceVenafiCertificate() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: resourceVenafiCertificateImport, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(180 * time.Second), + Read: schema.DefaultTimeout(180 * time.Second), + Default: schema.DefaultTimeout(180 * time.Second), + }, } } @@ -272,7 +278,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 +634,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 +819,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 +849,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