Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions docs/resources/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ resource "kubernetes_pod" "dev" {
- `api_key_scope` (String) Controls what API routes the agent token can access. Options: `all` (full access) or `no_user_data` (blocks `/external-auth`, `/gitsshkey`, and `/gitauth` routes)
- `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.
- `dir` (String, Deprecated) The starting directory when a user creates a shell session. Defaults to `"$HOME"`.

~> **Warning:** This attribute is deprecated and will be removed in a future release. Setting `dir` to a value other than `$HOME` will break [Coder Desktop file sync](https://coder.com/docs/user-guides/desktop/desktop-connect-sync).
- `dir` (String) The starting directory when a user creates a shell session. Defaults to `"$HOME"`. SFTP and scp resolve relative and `~/`-prefixed paths against this directory, so use absolute paths for file transfers.
- `display_apps` (Block Set, Max: 1) The list of built-in apps to display in the agent bar. (see [below for nested schema](#nestedblock--display_apps))
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
- `metadata` (Block List) Each `metadata` block defines a single item consisting of a key/value pair. This feature is in alpha and may break in future releases. (see [below for nested schema](#nestedblock--metadata))
Expand Down
30 changes: 12 additions & 18 deletions provider/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func agentResource() *schema.Resource {
return diag.FromErr(err)
}
}
return updateInitScript(resourceData, i)
},

return updateInitScript(resourceData, i)
},
ReadWithoutTimeout: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
token := agentAuthToken(ctx, "")
err := resourceData.Set("token", token)
Expand All @@ -74,9 +74,8 @@ func agentResource() *schema.Resource {
}
}

return updateInitScript(resourceData, i)
},

return updateInitScript(resourceData, i)
},
DeleteContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
return nil
},
Expand Down Expand Up @@ -112,22 +111,17 @@ func agentResource() *schema.Resource {
Description: "The authentication type the agent will use. Must be one of: `\"token\"`, `\"google-instance-identity\"`, `\"aws-instance-identity\"`, `\"azure-instance-identity\"`.",
ValidateFunc: validation.StringInSlice([]string{"token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity"}, false),
},
"dir": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Deprecated: "dir has been deprecated and will be removed in a future release.",
Description: "The starting directory when a user creates a shell session. Defaults to `\"$HOME\"`." +
"\n\n~> **Warning:** This attribute is deprecated and will be removed in a future release. " +
"Setting `dir` to a value other than `$HOME` will break " +
"[Coder Desktop file sync](https://coder.com/docs/user-guides/desktop/desktop-connect-sync).",
ValidateFunc: helpers.WarnDirNotHome,
},

"dir": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "The starting directory when a user creates a shell session. Defaults to `\"$HOME\"`. " +
"SFTP and scp resolve relative and `~/`-prefixed paths against this directory, " +
"so use absolute paths for file transfers.",
},
"env": {
ForceNew: true,
Description: "A mapping of environment variables to set inside the workspace.",

Type: schema.TypeMap,
Optional: true,
},
Expand Down
14 changes: 0 additions & 14 deletions provider/helpers/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ func ValidateURL(value any, label string) ([]string, []error) {
return nil, nil
}

// WarnDirNotHome returns a warning if dir is set to a value other
// than $HOME, because this breaks Coder Desktop file sync. The dir
// attribute is deprecated and will be removed in a future release.
func WarnDirNotHome(val interface{}, _ string) ([]string, []error) {
d, ok := val.(string)
if !ok || d == "" || d == "$HOME" || d == "~" {
return nil, nil
}
return []string{
`"dir" is deprecated and will be removed in a future release.`,
`Setting "dir" to a value other than $HOME will break Coder Desktop file sync.`,
}, nil
}

// ValidateExternalURL validates that value is a URL the browser's URL can parse.
// An external app URL must carry a scheme and hostname
func ValidateExternalURL(value string) error {
Expand Down
54 changes: 0 additions & 54 deletions provider/helpers/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,60 +150,6 @@ func TestValidateURL(t *testing.T) {
}
}

func TestWarnDirNotHome(t *testing.T) {
tests := []struct {
name string
value interface{}
warnCount int
}{
// No warnings expected.
{
name: "empty string",
value: "",
warnCount: 0,
},
{
name: "$HOME",
value: "$HOME",
warnCount: 0,
},
{
name: "tilde",
value: "~",
warnCount: 0,
},
{
name: "non-string type",
value: 123,
warnCount: 0,
},
// Warnings expected.
{
name: "absolute path",
value: "/workspace",
warnCount: 2,
},
{
name: "relative path",
value: "projects/foo",
warnCount: 2,
},
{
name: "tilde subdir",
value: "~/projects",
warnCount: 2,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
warnings, errors := WarnDirNotHome(tt.value, "dir")
require.Empty(t, errors, "expected no errors")
require.Len(t, warnings, tt.warnCount)
})
}
}

func TestValidateExternalURL(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading