Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ terraform {
}

provider "coderd" {
url = "coder.example.com"
url = "https://coder.example.com"
token = "****"
}

Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ terraform {
}

provider "coderd" {
url = "coder.example.com"
url = "https://coder.example.com"
token = "****"
}

Expand Down
12 changes: 11 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"fmt"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -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)
Comment on lines +105 to +114
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil {
resp.Diagnostics.AddError("url", "url is not a valid URL: "+err.Error())
return
Expand Down
Loading