Skip to content

Commit

Permalink
Revert "fix: Add custom host for access URL and remove access port (#40
Browse files Browse the repository at this point in the history
…)" (#42)

This reverts commit cea1dfa.
  • Loading branch information
kylecarbs authored Aug 18, 2022
1 parent cea1dfa commit b8bdb6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
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
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ description: |-

# Coder Provider

-> This works with a closed-alpha of [Coder](https://coder.com). For access, contact [support@coder.com](mailto:support@coder.com).

## Example

```terraform
Expand Down Expand Up @@ -64,5 +62,4 @@ resource "google_compute_instance" "dev" {

### Optional

- `host` (String) This overrides the host in the "url" property, but preserve the port.
- `url` (String) The URL to access Coder.
32 changes: 19 additions & 13 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 @@ -40,11 +41,6 @@ func New() *schema.Provider {
return nil, nil
},
},
"host": {
Type: schema.TypeString,
Description: "This overrides the host in the \"url\" property, but preserve the port.",
Optional: true,
},
},
ConfigureContextFunc: func(c context.Context, resourceData *schema.ResourceData) (interface{}, diag.Diagnostics) {
rawURL, ok := resourceData.Get("url").(string)
Expand All @@ -58,14 +54,6 @@ func New() *schema.Provider {
if err != nil {
return nil, diag.FromErr(err)
}
rawHost, ok := resourceData.Get("host").(string)
if ok {
rawPort := parsed.Port()
if rawPort != "" && !strings.Contains(rawHost, ":") {
rawHost += ":" + rawPort
}
parsed.Host = rawHost
}
return config{
URL: parsed,
}, nil
Expand Down Expand Up @@ -119,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 @@ -127,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: 1 addition & 2 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func TestWorkspace(t *testing.T) {
Config: `
provider "coder" {
url = "https://example.com:8080"
host = "localhost:4334"
}
data "coder_workspace" "me" {
}`,
Expand All @@ -46,7 +45,7 @@ func TestWorkspace(t *testing.T) {
value := attribs["transition"]
require.NotNil(t, value)
t.Log(value)
require.Equal(t, "https://localhost:4334", attribs["access_url"])
require.Equal(t, "8080", attribs["access_port"])
require.Equal(t, "owner123", attribs["owner"])
require.Equal(t, "owner123@example.com", attribs["owner_email"])
return nil
Expand Down

0 comments on commit b8bdb6b

Please sign in to comment.