diff --git a/internal/provider/client.go b/internal/provider/client.go index 1665661..2692bd2 100644 --- a/internal/provider/client.go +++ b/internal/provider/client.go @@ -17,6 +17,7 @@ const DefaultURL string = "http://localhost:8080" type Client struct { HTTPClient *http.Client Url string + Timeout int64 Username *string Password *string Jwt *string @@ -31,9 +32,9 @@ type RequestError struct { Err error } -func NewClient(url string, username *string, password *string, jwt *string, apiToken *string, extraHeaders *interface{}, tenantId *string, keepOriginalSource *bool) (*Client, error) { +func NewClient(url string, timeout int64, username *string, password *string, jwt *string, apiToken *string, extraHeaders *interface{}, tenantId *string, keepOriginalSource *bool) (*Client, error) { c := Client{ - HTTPClient: &http.Client{Timeout: 10 * time.Second}, + HTTPClient: &http.Client{Timeout: time.Duration(timeout) * time.Second}, Url: DefaultURL, } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index c5200df..c633313 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -54,6 +54,13 @@ func New(version string, tenant *string) func() *schema.Provider { Description: "The BasicAuth password", DefaultFunc: schema.EnvDefaultFunc("KESTRA_PASSWORD", ""), }, + "timeout": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + Sensitive: false, + Description: "The timeout (in seconds) for http requests", + DefaultFunc: schema.EnvDefaultFunc("KESTRA_TIMEOUT", 10), + }, "jwt": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -116,6 +123,7 @@ func New(version string, tenant *string) func() *schema.Provider { p.ConfigureContextFunc = func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { url := strings.TrimRight(d.Get("url").(string), "/") + timeout := d.Get("timeout").(int64) username := d.Get("username").(string) password := d.Get("password").(string) jwt := d.Get("jwt").(string) @@ -132,7 +140,7 @@ func New(version string, tenant *string) func() *schema.Provider { var diags diag.Diagnostics - c, err := NewClient(url, &username, &password, &jwt, &apiToken, &extraHeaders, &tenantId, &keepOriginalSource) + c, err := NewClient(url, timeout, &username, &password, &jwt, &apiToken, &extraHeaders, &tenantId, &keepOriginalSource) if err != nil { return nil, diag.FromErr(err) } diff --git a/internal/provider/resource_kv_test.go b/internal/provider/resource_kv_test.go index 641909d..1c78e18 100644 --- a/internal/provider/resource_kv_test.go +++ b/internal/provider/resource_kv_test.go @@ -185,7 +185,7 @@ func TestAccKv(t *testing.T) { urlEnv := strings.TrimRight(os.Getenv("KESTRA_URL"), "/") usernameEnv := os.Getenv("KESTRA_USERNAME") passwordEnv := os.Getenv("KESTRA_PASSWORD") - c, _ := NewClient(urlEnv, &usernameEnv, &passwordEnv, nil, nil, nil, nil, nil) + c, _ := NewClient(urlEnv, 10, &usernameEnv, &passwordEnv, nil, nil, nil, nil, nil) url := c.Url + fmt.Sprintf("%s/namespaces/io.kestra.terraform/kv/string", apiRoot(nil)) request, _ := http.NewRequest("GET", url, nil) _, _, httpError := c.rawResponseRequest("GET", request)