Skip to content

Commit b755144

Browse files
authored
feat: Add path-based routing for applications (#21)
This adds a `path` parameter that specifies whether the URL provided will be accessed via the wildcard or relative path.
1 parent 222e55a commit b755144

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

Diff for: Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ fmt:
44
terraform fmt -recursive
55

66
gen:
7-
# go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
8-
tfplugindocs
7+
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
98

109
# Run acceptance tests
1110
.PHONY: testacc

Diff for: docs/resources/agent.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ resource "kubernetes_pod" "dev" {
4949
- `auth` (String) The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
5050
- `dir` (String) The starting directory when a user creates a shell session. Defaults to $HOME.
5151
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
52-
- `id` (String) The ID of this resource.
5352
- `startup_script` (String) A script to run after the agent starts.
5453

5554
### Read-Only
5655

56+
- `id` (String) The ID of this resource.
5757
- `init_script` (String) Run this script on startup of an instance to initialize the agent.
5858
- `token` (String) Set the environment variable "CODER_AGENT_TOKEN" with this token to authenticate an agent.
5959

Diff for: docs/resources/agent_instance.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ resource "coder_agent_instance" "dev" {
3737
- `agent_id` (String) The "id" property of a "coder_agent" resource to associate with.
3838
- `instance_id` (String) The instance identifier of a provisioned resource.
3939

40-
### Optional
40+
### Read-Only
4141

4242
- `id` (String) The ID of this resource.
4343

Diff for: docs/resources/app.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ resource "coder_app" "code-server" {
2929
agent_id = coder_agent.dev.id
3030
name = "VS Code"
3131
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
32-
target = "http://localhost:13337"
32+
url = "http://localhost:13337"
33+
path = true
3334
}
3435
3536
resource "coder_app" "vim" {
@@ -56,10 +57,14 @@ resource "coder_app" "intellij" {
5657

5758
### Optional
5859

59-
- `command` (String) A command to run in a terminal opening this app. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command. Either "command" or "target" may be specified, but not both.
60+
- `command` (String) A command to run in a terminal opening this app. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command. Either "command" or "url" may be specified, but not both.
6061
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icons. Use a built-in icon with `data.coder_workspace.me.access_url + "/icons/<path>"`.
61-
- `id` (String) The ID of this resource.
6262
- `name` (String) A display name to identify the app.
63-
- `target` (String) A URL to be proxied to from inside the workspace. Either "command" or "target" may be specified, but not both.
63+
- `relative_path` (Boolean) Specifies whether the URL will be accessed via a relative path or wildcard. Use if wildcard routing is unavailable.
64+
- `url` (String) A URL to be proxied to from inside the workspace. Either "command" or "url" may be specified, but not both.
65+
66+
### Read-Only
67+
68+
- `id` (String) The ID of this resource.
6469

6570

Diff for: examples/resources/coder_app/resource.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ resource "coder_app" "code-server" {
1414
agent_id = coder_agent.dev.id
1515
name = "VS Code"
1616
icon = data.coder_workspace.me.access_url + "/icons/vscode.svg"
17-
target = "http://localhost:13337"
17+
url = "http://localhost:13337"
18+
path = true
1819
}
1920

2021
resource "coder_app" "vim" {

Diff for: internal/provider/provider.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func New() *schema.Provider {
260260
Type: schema.TypeString,
261261
Description: "A command to run in a terminal opening this app. In the web, " +
262262
"this will open in a new tab. In the CLI, this will SSH and execute the command. " +
263-
"Either \"command\" or \"target\" may be specified, but not both.",
264-
ConflictsWith: []string{"target"},
263+
"Either \"command\" or \"url\" may be specified, but not both.",
264+
ConflictsWith: []string{"url"},
265265
Optional: true,
266266
ForceNew: true,
267267
},
@@ -286,10 +286,18 @@ func New() *schema.Provider {
286286
ForceNew: true,
287287
Optional: true,
288288
},
289-
"target": {
289+
"relative_path": {
290+
Type: schema.TypeBool,
291+
Description: "Specifies whether the URL will be accessed via a relative " +
292+
"path or wildcard. Use if wildcard routing is unavailable.",
293+
ForceNew: true,
294+
Optional: true,
295+
ConflictsWith: []string{"command"},
296+
},
297+
"url": {
290298
Type: schema.TypeString,
291299
Description: "A URL to be proxied to from inside the workspace. " +
292-
"Either \"command\" or \"target\" may be specified, but not both.",
300+
"Either \"command\" or \"url\" may be specified, but not both.",
293301
ForceNew: true,
294302
Optional: true,
295303
ConflictsWith: []string{"command"},

Diff for: internal/provider/provider_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ func TestApp(t *testing.T) {
154154
agent_id = coder_agent.dev.id
155155
name = "code-server"
156156
icon = "builtin:vim"
157-
target = "http://localhost:13337"
157+
relative_path = true
158+
url = "http://localhost:13337"
158159
}
159160
`,
160161
Check: func(state *terraform.State) error {
@@ -166,7 +167,8 @@ func TestApp(t *testing.T) {
166167
"agent_id",
167168
"name",
168169
"icon",
169-
"target",
170+
"relative_path",
171+
"url",
170172
} {
171173
value := resource.Primary.Attributes[key]
172174
t.Logf("%q = %q", key, value)

0 commit comments

Comments
 (0)