diff --git a/docs/index.md b/docs/index.md index 3d9be49..79df017 100644 --- a/docs/index.md +++ b/docs/index.md @@ -27,7 +27,7 @@ terraform { } provider "coderd" { - url = "coder.example.com" + url = "https://coder.example.com" token = "****" } diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index fe3b9dc..d50d5e7 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -7,7 +7,7 @@ terraform { } provider "coderd" { - url = "coder.example.com" + url = "https://coder.example.com" token = "****" } diff --git a/integration/integration.go b/integration/integration.go index f2ed0dd..89b385d 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -95,7 +95,7 @@ func StartCoder(ctx context.Context, t *testing.T, name string, useLicense bool) t.Logf("not ready yet: %s", err.Error()) } return err == nil - }, 15*time.Second, time.Second, "coder failed to become ready in time") + }, 20*time.Second, time.Second, "coder failed to become ready in time") _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{ Email: testEmail, Username: testUsername, diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b8b9fa7..b7cfe88 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -2,6 +2,7 @@ package provider import ( "context" + "fmt" "net/url" "os" "strings" @@ -101,7 +102,16 @@ func (p *CoderdProvider) Configure(ctx context.Context, req provider.ConfigureRe data.Token = types.StringValue(tokenEnv) } - url, err := url.Parse(data.URL.ValueString()) + rawURL := data.URL.ValueString() + if !strings.HasPrefix(rawURL, "http://") && !strings.HasPrefix(rawURL, "https://") { + scheme := "https" + if strings.HasPrefix(rawURL, "localhost") { + scheme = "http" + } + rawURL = fmt.Sprintf("%s://%s", scheme, rawURL) + } + + url, err := url.Parse(rawURL) if err != nil { resp.Diagnostics.AddError("url", "url is not a valid URL: "+err.Error()) return