Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 047c203

Browse files
committed
docs: add URL scheme to example
1 parent 48cd700 commit 047c203

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
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

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)