Skip to content

Commit cea1dfa

Browse files
authored
fix: Add custom host for access URL and remove access port (#40)
This allows a host override, which is useful for running Docker containers that need to access the same deployment port, but on `host.docker.internal` as the hostname. It also removes access port, which was released a few days ago in hopes of solving the same problem, but never really did. It doesn't seem likely to be used yet, so it feels safe to remove.
1 parent 0e3bb2b commit cea1dfa

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

Diff for: docs/data-sources/workspace.md

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ resource "kubernetes_pod" "dev" {
2626

2727
### Read-Only
2828

29-
- `access_port` (Number) The access port of the Coder deployment provisioning this workspace.
3029
- `access_url` (String) The access URL of the Coder deployment provisioning this workspace.
3130
- `id` (String) UUID of the workspace.
3231
- `name` (String) Name of the workspace.

Diff for: docs/index.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: |-
88

99
# Coder Provider
1010

11+
-> This works with a closed-alpha of [Coder](https://coder.com). For access, contact [[email protected]](mailto:[email protected]).
12+
1113
## Example
1214

1315
```terraform
@@ -62,4 +64,5 @@ resource "google_compute_instance" "dev" {
6264

6365
### Optional
6466

67+
- `host` (String) This overrides the host in the "url" property, but preserve the port.
6568
- `url` (String) The URL to access Coder.

Diff for: internal/provider/provider.go

+13-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"reflect"
1010
"runtime"
11-
"strconv"
1211
"strings"
1312

1413
"github.com/google/uuid"
@@ -41,6 +40,11 @@ func New() *schema.Provider {
4140
return nil, nil
4241
},
4342
},
43+
"host": {
44+
Type: schema.TypeString,
45+
Description: "This overrides the host in the \"url\" property, but preserve the port.",
46+
Optional: true,
47+
},
4448
},
4549
ConfigureContextFunc: func(c context.Context, resourceData *schema.ResourceData) (interface{}, diag.Diagnostics) {
4650
rawURL, ok := resourceData.Get("url").(string)
@@ -54,6 +58,14 @@ func New() *schema.Provider {
5458
if err != nil {
5559
return nil, diag.FromErr(err)
5660
}
61+
rawHost, ok := resourceData.Get("host").(string)
62+
if ok {
63+
rawPort := parsed.Port()
64+
if rawPort != "" && !strings.Contains(rawHost, ":") {
65+
rawHost += ":" + rawPort
66+
}
67+
parsed.Host = rawHost
68+
}
5769
return config{
5870
URL: parsed,
5971
}, nil
@@ -107,19 +119,6 @@ func New() *schema.Provider {
107119
}
108120
rd.Set("access_url", config.URL.String())
109121

110-
rawPort := config.URL.Port()
111-
if rawPort == "" {
112-
rawPort = "80"
113-
if config.URL.Scheme == "https" {
114-
rawPort = "443"
115-
}
116-
}
117-
port, err := strconv.Atoi(rawPort)
118-
if err != nil {
119-
return diag.Errorf("couldn't parse port %q", port)
120-
}
121-
rd.Set("access_port", port)
122-
123122
return nil
124123
},
125124
Schema: map[string]*schema.Schema{
@@ -128,11 +127,6 @@ func New() *schema.Provider {
128127
Computed: true,
129128
Description: "The access URL of the Coder deployment provisioning this workspace.",
130129
},
131-
"access_port": {
132-
Type: schema.TypeInt,
133-
Computed: true,
134-
Description: "The access port of the Coder deployment provisioning this workspace.",
135-
},
136130
"start_count": {
137131
Type: schema.TypeInt,
138132
Computed: true,

Diff for: internal/provider/provider_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestWorkspace(t *testing.T) {
3232
Config: `
3333
provider "coder" {
3434
url = "https://example.com:8080"
35+
host = "localhost:4334"
3536
}
3637
data "coder_workspace" "me" {
3738
}`,
@@ -45,7 +46,7 @@ func TestWorkspace(t *testing.T) {
4546
value := attribs["transition"]
4647
require.NotNil(t, value)
4748
t.Log(value)
48-
require.Equal(t, "8080", attribs["access_port"])
49+
require.Equal(t, "https://localhost:4334", attribs["access_url"])
4950
require.Equal(t, "owner123", attribs["owner"])
5051
require.Equal(t, "[email protected]", attribs["owner_email"])
5152
return nil

0 commit comments

Comments
 (0)