mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -124,6 +124,8 @@ func (t *terraform) Provision(stream proto.DRPCProvisioner_ProvisionStream) erro
|
||||
"CODER_WORKSPACE_TRANSITION="+strings.ToLower(start.Metadata.WorkspaceTransition.String()),
|
||||
"CODER_WORKSPACE_NAME="+start.Metadata.WorkspaceName,
|
||||
"CODER_WORKSPACE_OWNER="+start.Metadata.WorkspaceOwner,
|
||||
"CODER_WORKSPACE_ID="+start.Metadata.WorkspaceId,
|
||||
"CODER_WORKSPACE_OWNER_ID="+start.Metadata.WorkspaceOwnerId,
|
||||
)
|
||||
for key, value := range provisionersdk.AgentScriptEnv() {
|
||||
env = append(env, key+"="+value)
|
||||
@@ -330,6 +332,12 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
|
||||
agent.StartupScript = startupScript
|
||||
}
|
||||
}
|
||||
if directoryRaw, has := resource.Expressions["dir"]; has {
|
||||
dir, ok := directoryRaw.ConstantValue.(string)
|
||||
if ok {
|
||||
agent.Directory = dir
|
||||
}
|
||||
}
|
||||
|
||||
agents[resource.Address] = agent
|
||||
}
|
||||
@@ -381,6 +389,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
|
||||
Auth string `mapstructure:"auth"`
|
||||
OperatingSystem string `mapstructure:"os"`
|
||||
Architecture string `mapstructure:"arch"`
|
||||
Directory string `mapstructure:"dir"`
|
||||
ID string `mapstructure:"id"`
|
||||
Token string `mapstructure:"token"`
|
||||
Env map[string]string `mapstructure:"env"`
|
||||
@@ -405,6 +414,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
|
||||
StartupScript: attrs.StartupScript,
|
||||
OperatingSystem: attrs.OperatingSystem,
|
||||
Architecture: attrs.Architecture,
|
||||
Directory: attrs.Directory,
|
||||
}
|
||||
switch attrs.Auth {
|
||||
case "token":
|
||||
|
||||
@@ -160,6 +160,7 @@ provider "coder" {
|
||||
resource "coder_agent" "A" {
|
||||
os = "windows"
|
||||
arch = "arm64"
|
||||
dir = "C:\\System32"
|
||||
}
|
||||
resource "null_resource" "A" {
|
||||
depends_on = [
|
||||
@@ -184,6 +185,7 @@ provider "coder" {
|
||||
Name: "A",
|
||||
OperatingSystem: "windows",
|
||||
Architecture: "arm64",
|
||||
Directory: "C:\\System32",
|
||||
Auth: &proto.Agent_Token{
|
||||
Token: "",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user