Skip to content

Commit f14f186

Browse files
committed
feat: add default_apps field to agent
- Enables a template admin to configure which apps are displayed to the user in the dashboard.
1 parent 188ffef commit f14f186

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

docs/resources/agent.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ resource "kubernetes_pod" "dev" {
4848

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
- `connection_timeout` (Number) Time in seconds until the agent is marked as timed out when a connection with the server cannot be established. A value of zero never marks the agent as timed out.
51+
- `default_apps` (List of String) The list of built-in apps to display in the UI. Defaults to all apps.
5152
- `dir` (String) The starting directory when a user creates a shell session. Defaults to $HOME.
5253
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
5354
- `login_before_ready` (Boolean, Deprecated) This option defines whether or not the user can (by default) login to the workspace before it is ready. Ready means that e.g. the startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.

provider/agent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ func agentResource() *schema.Resource {
198198
},
199199
},
200200
},
201+
"default_apps": {
202+
Type: schema.TypeList,
203+
Description: "The list of built-in apps to display in the UI. Defaults to all apps.",
204+
ForceNew: true,
205+
Optional: true,
206+
Elem: &schema.Schema{
207+
Type: schema.TypeString,
208+
},
209+
},
201210
},
202211
}
203212
}

provider/agent_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider_test
22

33
import (
4+
"fmt"
45
"regexp"
56
"testing"
67

@@ -247,3 +248,49 @@ func TestAgent_Metadata(t *testing.T) {
247248
}},
248249
})
249250
}
251+
252+
func TestAgent_DefaultApps(t *testing.T) {
253+
t.Parallel()
254+
resource.Test(t, resource.TestCase{
255+
Providers: map[string]*schema.Provider{
256+
"coder": provider.New(),
257+
},
258+
IsUnitTest: true,
259+
Steps: []resource.TestStep{{
260+
Config: `
261+
provider "coder" {
262+
url = "https://example.com"
263+
}
264+
resource "coder_agent" "dev" {
265+
os = "linux"
266+
arch = "amd64"
267+
default_apps = ["web-terminal", "vscode-desktop", "code-server", "port-forward"]
268+
}
269+
`,
270+
Check: func(state *terraform.State) error {
271+
require.Len(t, state.Modules, 1)
272+
require.Len(t, state.Modules[0].Resources, 1)
273+
274+
resource := state.Modules[0].Resources["coder_agent.dev"]
275+
require.NotNil(t, resource)
276+
277+
t.Logf("resource: %v", resource.Primary.Attributes)
278+
279+
numElements, ok := resource.Primary.Attributes["default_apps.#"]
280+
require.True(t, ok)
281+
require.Equal(t, "4", numElements)
282+
283+
for i, app := range []string{
284+
"web-terminal",
285+
"vscode-desktop",
286+
"code-server",
287+
"port-forward",
288+
} {
289+
key := fmt.Sprintf("default_apps.%d", i)
290+
require.Equal(t, resource.Primary.Attributes[key], app)
291+
}
292+
return nil
293+
},
294+
}},
295+
})
296+
}

0 commit comments

Comments
 (0)