Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83102e7

Browse files
committed
feat: Add DevURL support
This adds what are presently named "devurls" in v1.It seems this may be a dated term, since this allowsmuch more than accessing applications via URL."coder open <name>" will launch any _devurls_ definedhere. If in the web, it'll open either a web terminal orport forward to the desired application. If in the terminal,it'll open the browser, or launch the command over SSH.
1 parenta336507 commit83102e7

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

‎docs/resources/devurl.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title:"coder_devurl Resource - terraform-provider-coder"
4+
subcategory:""
5+
description:|-
6+
Use this resource to define shortcuts to access applications in a workspace.
7+
---
8+
9+
#coder_devurl (Resource)
10+
11+
Use this resource to define shortcuts to access applications in a workspace.
12+
13+
##Example Usage
14+
15+
```terraform
16+
resource "coder_agent" "dev" {
17+
os = "linux"
18+
arch = "amd64"
19+
dir = "/workspace"
20+
startup_script = <<EOF
21+
curl -fsSL https://code-server.dev/install.sh | sh
22+
code-server --auth none --port 13337
23+
EOF
24+
}
25+
26+
resource "coder_devurl" "code-server" {
27+
agent_id = coder_agent.dev.id
28+
name = "VS Code"
29+
icon = "builtin:vscode"
30+
target = "http://localhost:13337"
31+
}
32+
33+
resource "coder_devurl" "vim" {
34+
agent_id = coder_agent.dev.id
35+
name = "Vim"
36+
icon = "builtin:vim"
37+
command = "vim"
38+
}
39+
40+
resource "coder_devurl" "intellij" {
41+
agent_id = coder_agent.dev.id
42+
icon = "builtin:intellij"
43+
name = "JetBrains IntelliJ"
44+
command = "projector run"
45+
}
46+
```
47+
48+
<!-- schema generated by tfplugindocs-->
49+
##Schema
50+
51+
###Required
52+
53+
-`agent_id` (String) The "id" property of a "coder_agent" resource to associate with.
54+
55+
###Optional
56+
57+
-`command` (String) A command to run in a terminal opening this DevURL. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command.
58+
-`icon` (String) An icon to display in the dashboard.
59+
-`id` (String) The ID of this resource.
60+
-`name` (String) A display name to identify the DevURL.
61+
-`target` (String) A URL to be proxied to from inside the workspace.
62+
63+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
resource"coder_agent""dev" {
2+
os="linux"
3+
arch="amd64"
4+
dir="/workspace"
5+
startup_script=<<EOF
6+
curl -fsSL https://code-server.dev/install.sh | sh
7+
code-server --auth none --port 13337
8+
EOF
9+
}
10+
11+
resource"coder_devurl""code-server" {
12+
agent_id=coder_agent.dev.id
13+
name="VS Code"
14+
icon="builtin:vscode"
15+
target="http://localhost:13337"
16+
}
17+
18+
resource"coder_devurl""vim" {
19+
agent_id=coder_agent.dev.id
20+
name="Vim"
21+
icon="builtin:vim"
22+
command="vim"
23+
}
24+
25+
resource"coder_devurl""intellij" {
26+
agent_id=coder_agent.dev.id
27+
icon="builtin:intellij"
28+
name="JetBrains IntelliJ"
29+
command="projector run"
30+
}

‎internal/provider/provider.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,54 @@ func New() *schema.Provider {
227227
},
228228
},
229229
},
230+
"coder_devurl": {
231+
Description:"Use this resource to define shortcuts to access applications in a workspace.",
232+
CreateContext:func(c context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
233+
resourceData.SetId(uuid.NewString())
234+
returnnil
235+
},
236+
ReadContext:func(c context.Context,resourceData*schema.ResourceData,iinterface{}) diag.Diagnostics {
237+
returnnil
238+
},
239+
DeleteContext:func(ctx context.Context,rd*schema.ResourceData,iinterface{}) diag.Diagnostics {
240+
returnnil
241+
},
242+
Schema:map[string]*schema.Schema{
243+
"agent_id": {
244+
Type:schema.TypeString,
245+
Description:`The "id" property of a "coder_agent" resource to associate with.`,
246+
ForceNew:true,
247+
Required:true,
248+
},
249+
"name": {
250+
Type:schema.TypeString,
251+
Description:"A display name to identify the DevURL.",
252+
ForceNew:true,
253+
Optional:true,
254+
},
255+
"icon": {
256+
Type:schema.TypeString,
257+
Description:"An icon to display in the dashboard.",
258+
ForceNew:true,
259+
Optional:true,
260+
},
261+
"command": {
262+
Type:schema.TypeString,
263+
Description:"A command to run in a terminal opening this DevURL. In the web, "+
264+
"this will open in a new tab. In the CLI, this will SSH and execute the command.",
265+
ConflictsWith: []string{"target"},
266+
Optional:true,
267+
ForceNew:true,
268+
},
269+
"target": {
270+
Type:schema.TypeString,
271+
Description:"A URL to be proxied to from inside the workspace.",
272+
ForceNew:true,
273+
Optional:true,
274+
ConflictsWith: []string{"command"},
275+
},
276+
},
277+
},
230278
},
231279
}
232280
}

‎internal/provider/provider_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,47 @@ func TestAgentInstance(t *testing.T) {
134134
}},
135135
})
136136
}
137+
138+
funcTestDevURL(t*testing.T) {
139+
t.Parallel()
140+
resource.Test(t, resource.TestCase{
141+
Providers:map[string]*schema.Provider{
142+
"coder":provider.New(),
143+
},
144+
IsUnitTest:true,
145+
Steps: []resource.TestStep{{
146+
Config:`
147+
provider "coder" {
148+
}
149+
resource "coder_agent" "dev" {
150+
os = "linux"
151+
arch = "amd64"
152+
}
153+
resource "coder_devurl" "code-server" {
154+
agent_id = coder_agent.dev.id
155+
name = "code-server"
156+
icon = "builtin:vim"
157+
target = "http://localhost:13337"
158+
}
159+
`,
160+
Check:func(state*terraform.State)error {
161+
require.Len(t,state.Modules,1)
162+
require.Len(t,state.Modules[0].Resources,2)
163+
resource:=state.Modules[0].Resources["coder_devurl.code-server"]
164+
require.NotNil(t,resource)
165+
for_,key:=range []string{
166+
"agent_id",
167+
"name",
168+
"icon",
169+
"target",
170+
} {
171+
value:=resource.Primary.Attributes[key]
172+
t.Logf("%q = %q",key,value)
173+
require.NotNil(t,value)
174+
require.Greater(t,len(value),0)
175+
}
176+
returnnil
177+
},
178+
}},
179+
})
180+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp