Skip to content

Commit 9975301

Browse files
authored
feat: Expose access_port on coder_workspace to allow for alternative hosts (#37)
This allows our Docker template to use a custom host with the correct port.
1 parent 5e9c0be commit 9975301

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/data-sources/workspace.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ resource "kubernetes_pod" "dev" {
2626

2727
### Read-Only
2828

29+
- `access_port` (Number) The access port of the Coder deployment provisioning this workspace.
2930
- `access_url` (String) The access URL of the Coder deployment provisioning this workspace.
3031
- `id` (String) UUID of the workspace.
3132
- `name` (String) Name of the workspace.

internal/provider/provider.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"reflect"
1010
"runtime"
11+
"strconv"
1112
"strings"
1213

1314
"github.com/google/uuid"
@@ -106,6 +107,19 @@ func New() *schema.Provider {
106107
}
107108
rd.Set("access_url", config.URL.String())
108109

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+
109123
return nil
110124
},
111125
Schema: map[string]*schema.Schema{
@@ -114,6 +128,11 @@ func New() *schema.Provider {
114128
Computed: true,
115129
Description: "The access URL of the Coder deployment provisioning this workspace.",
116130
},
131+
"access_port": {
132+
Type: schema.TypeInt,
133+
Computed: true,
134+
Description: "The access port of the Coder deployment provisioning this workspace.",
135+
},
117136
"start_count": {
118137
Type: schema.TypeInt,
119138
Computed: true,

internal/provider/provider_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestWorkspace(t *testing.T) {
3131
Steps: []resource.TestStep{{
3232
Config: `
3333
provider "coder" {
34-
url = "https://example.com"
34+
url = "https://example.com:8080"
3535
}
3636
data "coder_workspace" "me" {
3737
}`,
@@ -45,6 +45,7 @@ func TestWorkspace(t *testing.T) {
4545
value := attribs["transition"]
4646
require.NotNil(t, value)
4747
t.Log(value)
48+
require.Equal(t, "8080", attribs["access_port"])
4849
require.Equal(t, "owner123", attribs["owner"])
4950
require.Equal(t, "[email protected]", attribs["owner_email"])
5051
return nil

0 commit comments

Comments
 (0)