Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default_apps field to coder_agent resource #147

Merged
merged 10 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ resource "kubernetes_pod" "dev" {

- `auth` (String) The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
- `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.
- `default_apps` (List of String) The list of built-in apps to display in the UI. Defaults to all apps.
sreya marked this conversation as resolved.
Show resolved Hide resolved
- `dir` (String) The starting directory when a user creates a shell session. Defaults to $HOME.
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
- `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.
Expand Down
9 changes: 9 additions & 0 deletions provider/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ func agentResource() *schema.Resource {
},
},
},
"default_apps": {
Type: schema.TypeList,
Description: "The list of built-in apps to display in the UI. Defaults to all apps.",
ForceNew: true,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down
47 changes: 47 additions & 0 deletions provider/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider_test

import (
"fmt"
"regexp"
"testing"

Expand Down Expand Up @@ -247,3 +248,49 @@ func TestAgent_Metadata(t *testing.T) {
}},
})
}

func TestAgent_DefaultApps(t *testing.T) {
t.Parallel()
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"
}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
default_apps = ["web-terminal", "vscode-desktop", "code-server", "port-forward"]
}
`,
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["coder_agent.dev"]
require.NotNil(t, resource)

t.Logf("resource: %v", resource.Primary.Attributes)

numElements, ok := resource.Primary.Attributes["default_apps.#"]
require.True(t, ok)
require.Equal(t, "4", numElements)

for i, app := range []string{
"web-terminal",
"vscode-desktop",
"code-server",
"port-forward",
} {
key := fmt.Sprintf("default_apps.%d", i)
require.Equal(t, resource.Primary.Attributes[key], app)
}
return nil
},
}},
})
}
Loading