Skip to content

feat: Expose access_port on coder_workspace to allow for alternative hosts #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resource "kubernetes_pod" "dev" {

### Read-Only

- `access_port` (Number) The access port of the Coder deployment provisioning this workspace.
- `access_url` (String) The access URL of the Coder deployment provisioning this workspace.
- `id` (String) UUID of the workspace.
- `name` (String) Name of the workspace.
Expand Down
19 changes: 19 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"reflect"
"runtime"
"strconv"
"strings"

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

rawPort := config.URL.Port()
if rawPort == "" {
rawPort = "80"
if config.URL.Scheme == "https" {
rawPort = "443"
}
}
port, err := strconv.Atoi(rawPort)
if err != nil {
return diag.Errorf("couldn't parse port %q", port)
}
rd.Set("access_port", port)

return nil
},
Schema: map[string]*schema.Schema{
Expand All @@ -114,6 +128,11 @@ func New() *schema.Provider {
Computed: true,
Description: "The access URL of the Coder deployment provisioning this workspace.",
},
"access_port": {
Type: schema.TypeInt,
Computed: true,
Description: "The access port of the Coder deployment provisioning this workspace.",
},
"start_count": {
Type: schema.TypeInt,
Computed: true,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestWorkspace(t *testing.T) {
Steps: []resource.TestStep{{
Config: `
provider "coder" {
url = "https://example.com"
url = "https://example.com:8080"
}
data "coder_workspace" "me" {
}`,
Expand All @@ -45,6 +45,7 @@ func TestWorkspace(t *testing.T) {
value := attribs["transition"]
require.NotNil(t, value)
t.Log(value)
require.Equal(t, "8080", attribs["access_port"])
require.Equal(t, "owner123", attribs["owner"])
require.Equal(t, "[email protected]", attribs["owner_email"])
return nil
Expand Down