Skip to content

Commit fc84e01

Browse files
docs: add URL scheme to example (#160)
Closes #159. This updates the documentation to include the access URL scheme in the example, matching the coder.com docs. It also implicitly adds the scheme to the provided access URL if not present, only prepending `http://` if the access URL is localhost. This is the same behaviour as `coder login`.
1 parent 48cd700 commit fc84e01

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ terraform {
2727
}
2828
2929
provider "coderd" {
30-
url = "coder.example.com"
30+
url = "https://coder.example.com"
3131
token = "****"
3232
}
3333

examples/provider/provider.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
}
88

99
provider "coderd" {
10-
url = "coder.example.com"
10+
url = "https://coder.example.com"
1111
token = "****"
1212
}
1313

integration/integration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func StartCoder(ctx context.Context, t *testing.T, name string, useLicense bool)
9595
t.Logf("not ready yet: %s", err.Error())
9696
}
9797
return err == nil
98-
}, 15*time.Second, time.Second, "coder failed to become ready in time")
98+
}, 20*time.Second, time.Second, "coder failed to become ready in time")
9999
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
100100
Email: testEmail,
101101
Username: testUsername,

internal/provider/provider.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56
"net/url"
67
"os"
78
"strings"
@@ -101,7 +102,16 @@ func (p *CoderdProvider) Configure(ctx context.Context, req provider.ConfigureRe
101102
data.Token = types.StringValue(tokenEnv)
102103
}
103104

104-
url, err := url.Parse(data.URL.ValueString())
105+
rawURL := data.URL.ValueString()
106+
if !strings.HasPrefix(rawURL, "http://") && !strings.HasPrefix(rawURL, "https://") {
107+
scheme := "https"
108+
if strings.HasPrefix(rawURL, "localhost") {
109+
scheme = "http"
110+
}
111+
rawURL = fmt.Sprintf("%s://%s", scheme, rawURL)
112+
}
113+
114+
url, err := url.Parse(rawURL)
105115
if err != nil {
106116
resp.Diagnostics.AddError("url", "url is not a valid URL: "+err.Error())
107117
return

0 commit comments

Comments
 (0)