Skip to content

Commit

Permalink
fix: Add custom host for access URL and remove access port (#44)
Browse files Browse the repository at this point in the history
* fix: Add custom host for access URL and remove access port

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.

* Fix access url when host is not provided

Signed-off-by: Spike Curtis <spike@coder.com>

Signed-off-by: Spike Curtis <spike@coder.com>
Co-authored-by: Spike Curtis <spike@coder.com>
Co-authored-by: Spike Curtis <spike@spikecurtis.com>
  • Loading branch information
3 people authored Aug 18, 2022
1 parent b8bdb6b commit 7172f9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func New() *schema.Provider {
if err != nil {
return nil, diag.FromErr(err)
}
rawHost, ok := resourceData.Get("host").(string)
if ok && rawHost != "" {
rawPort := parsed.Port()
if rawPort != "" && !strings.Contains(rawHost, ":") {
rawHost += ":" + rawPort
}
parsed.Host = rawHost
}
return config{
URL: parsed,
}, nil
Expand Down
29 changes: 29 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ func TestWorkspace(t *testing.T) {
},
}},
})
resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
url = "https://example.com:8080"
}
data "coder_workspace" "me" {
}`,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 1)
resource := state.Modules[0].Resources["data.coder_workspace.me"]
require.NotNil(t, resource)

attribs := resource.Primary.Attributes
value := attribs["transition"]
require.NotNil(t, value)
t.Log(value)
require.Equal(t, "https://example.com:8080", attribs["access_url"])
require.Equal(t, "owner123", attribs["owner"])
require.Equal(t, "owner123@example.com", attribs["owner_email"])
return nil
},
}},
})
}

func TestProvisioner(t *testing.T) {
Expand Down

0 comments on commit 7172f9c

Please sign in to comment.