Skip to content

Commit b8bdb6b

Browse files
authored
Revert "fix: Add custom host for access URL and remove access port (#40)" (#42)
This reverts commit cea1dfa.
1 parent cea1dfa commit b8bdb6b

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

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

+1
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.

Diff for: docs/index.md

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ 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-
1311
## Example
1412

1513
```terraform
@@ -64,5 +62,4 @@ resource "google_compute_instance" "dev" {
6462

6563
### Optional
6664

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

Diff for: internal/provider/provider.go

+19-13
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"
@@ -40,11 +41,6 @@ func New() *schema.Provider {
4041
return nil, nil
4142
},
4243
},
43-
"host": {
44-
Type: schema.TypeString,
45-
Description: "This overrides the host in the \"url\" property, but preserve the port.",
46-
Optional: true,
47-
},
4844
},
4945
ConfigureContextFunc: func(c context.Context, resourceData *schema.ResourceData) (interface{}, diag.Diagnostics) {
5046
rawURL, ok := resourceData.Get("url").(string)
@@ -58,14 +54,6 @@ func New() *schema.Provider {
5854
if err != nil {
5955
return nil, diag.FromErr(err)
6056
}
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-
}
6957
return config{
7058
URL: parsed,
7159
}, nil
@@ -119,6 +107,19 @@ func New() *schema.Provider {
119107
}
120108
rd.Set("access_url", config.URL.String())
121109

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+
122123
return nil
123124
},
124125
Schema: map[string]*schema.Schema{
@@ -127,6 +128,11 @@ func New() *schema.Provider {
127128
Computed: true,
128129
Description: "The access URL of the Coder deployment provisioning this workspace.",
129130
},
131+
"access_port": {
132+
Type: schema.TypeInt,
133+
Computed: true,
134+
Description: "The access port of the Coder deployment provisioning this workspace.",
135+
},
130136
"start_count": {
131137
Type: schema.TypeInt,
132138
Computed: true,

Diff for: internal/provider/provider_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func TestWorkspace(t *testing.T) {
3232
Config: `
3333
provider "coder" {
3434
url = "https://example.com:8080"
35-
host = "localhost:4334"
3635
}
3736
data "coder_workspace" "me" {
3837
}`,
@@ -46,7 +45,7 @@ func TestWorkspace(t *testing.T) {
4645
value := attribs["transition"]
4746
require.NotNil(t, value)
4847
t.Log(value)
49-
require.Equal(t, "https://localhost:4334", attribs["access_url"])
48+
require.Equal(t, "8080", attribs["access_port"])
5049
require.Equal(t, "owner123", attribs["owner"])
5150
require.Equal(t, "[email protected]", attribs["owner_email"])
5251
return nil

0 commit comments

Comments
 (0)