Skip to content

Commit 7172f9c

Browse files
fix: Add custom host for access URL and remove access port (#44)
* 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 <[email protected]> Signed-off-by: Spike Curtis <[email protected]> Co-authored-by: Spike Curtis <[email protected]> Co-authored-by: Spike Curtis <[email protected]>
1 parent b8bdb6b commit 7172f9c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

internal/provider/provider.go

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ func New() *schema.Provider {
5454
if err != nil {
5555
return nil, diag.FromErr(err)
5656
}
57+
rawHost, ok := resourceData.Get("host").(string)
58+
if ok && rawHost != "" {
59+
rawPort := parsed.Port()
60+
if rawPort != "" && !strings.Contains(rawHost, ":") {
61+
rawHost += ":" + rawPort
62+
}
63+
parsed.Host = rawHost
64+
}
5765
return config{
5866
URL: parsed,
5967
}, nil

internal/provider/provider_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@ func TestWorkspace(t *testing.T) {
5252
},
5353
}},
5454
})
55+
resource.Test(t, resource.TestCase{
56+
Providers: map[string]*schema.Provider{
57+
"coder": provider.New(),
58+
},
59+
IsUnitTest: true,
60+
Steps: []resource.TestStep{{
61+
Config: `
62+
provider "coder" {
63+
url = "https://example.com:8080"
64+
}
65+
data "coder_workspace" "me" {
66+
}`,
67+
Check: func(state *terraform.State) error {
68+
require.Len(t, state.Modules, 1)
69+
require.Len(t, state.Modules[0].Resources, 1)
70+
resource := state.Modules[0].Resources["data.coder_workspace.me"]
71+
require.NotNil(t, resource)
72+
73+
attribs := resource.Primary.Attributes
74+
value := attribs["transition"]
75+
require.NotNil(t, value)
76+
t.Log(value)
77+
require.Equal(t, "https://example.com:8080", attribs["access_url"])
78+
require.Equal(t, "owner123", attribs["owner"])
79+
require.Equal(t, "[email protected]", attribs["owner_email"])
80+
return nil
81+
},
82+
}},
83+
})
5584
}
5685

5786
func TestProvisioner(t *testing.T) {

0 commit comments

Comments
 (0)