feat: Update Terraform provider to support "dir" in "coder_agent" (#1219)

This allows users to specify a starting directory for shell sessions.
This commit is contained in:
Kyle Carberry
2022-05-02 10:27:34 -05:00
committed by GitHub
parent a79aa6418a
commit 8701e0084c
17 changed files with 233 additions and 145 deletions
+6
View File
@@ -49,6 +49,7 @@ type Metadata struct {
OwnerUsername string `json:"owner_username"`
EnvironmentVariables map[string]string `json:"environment_variables"`
StartupScript string `json:"startup_script"`
Directory string `json:"directory"`
}
type Dialer func(ctx context.Context, logger slog.Logger) (Metadata, *peerbroker.Listener, error)
@@ -340,6 +341,11 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
caller = "/c"
}
cmd := exec.CommandContext(ctx, shell, caller, command)
cmd.Dir = metadata.Directory
if cmd.Dir == "" {
// Default to $HOME if a directory is not set!
cmd.Dir = os.Getenv("HOME")
}
cmd.Env = append(os.Environ(), env...)
executablePath, err := os.Executable()
if err != nil {