Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(timeout): use timeout from plugin SDK #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions venafi/resource_venafi_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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),
},
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down