Skip to content

Commit add1d31

Browse files
committed
feat: Add startup_script_timeout and allow_login_before_ready
Ref: coder/coder#5749
1 parent bb057f8 commit add1d31

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

docs/resources/agent.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ resource "kubernetes_pod" "dev" {
4646

4747
### Optional
4848

49+
- `allow_login_before_ready` (Boolean) Allow users to login to the workspace before the agent is ready. Note that, when enabled, the agent could still be executing the startup script and the workspace in an incomplete state when logging in.
4950
- `auth` (String) The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
5051
- `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.
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
- `motd_file` (String) The path to a file within the workspace containing a message to display to users when they login via SSH. A typical value would be /etc/motd.
54-
- `shutdown_script` (String) A script to run before the agent is stopped.
55-
- `startup_script` (String) A script to run after the agent starts.
55+
- `shutdown_script` (String) A script to run before the agent is stopped. The script should exit when it is done to signal that the workspace can be stopped.
56+
- `startup_script` (String) A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready to accept connections.
57+
- `startup_script_timeout` (Number) Time in seconds until the agent ready status is marked as timed out, this happens when the startup script has not completed (exited) in the given time.
5658
- `troubleshooting_url` (String) A URL to a document with instructions for troubleshooting problems with the agent.
5759

5860
### Read-Only

provider/agent.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ func agentResource() *schema.Resource {
7777
},
7878
"startup_script": {
7979
ForceNew: true,
80-
Description: "A script to run after the agent starts.",
80+
Description: "A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready to accept connections.",
8181
Type: schema.TypeString,
8282
Optional: true,
8383
},
84+
"startup_script_timeout": {
85+
Type: schema.TypeInt,
86+
Default: 300,
87+
ForceNew: true,
88+
Optional: true,
89+
Description: "Time in seconds until the agent ready status is marked as timed out, this happens when the startup script has not completed (exited) in the given time.",
90+
ValidateFunc: validation.IntAtLeast(1),
91+
},
92+
"shutdown_script": {
93+
Type: schema.TypeString,
94+
ForceNew: true,
95+
Optional: true,
96+
Description: "A script to run before the agent is stopped. The script should exit when it is done to signal that the workspace can be stopped.",
97+
},
8498
"token": {
8599
ForceNew: true,
86100
Sensitive: true,
@@ -108,11 +122,12 @@ func agentResource() *schema.Resource {
108122
Optional: true,
109123
Description: "The path to a file within the workspace containing a message to display to users when they login via SSH. A typical value would be /etc/motd.",
110124
},
111-
"shutdown_script": {
125+
"allow_login_before_ready": {
126+
Type: schema.TypeBool,
127+
Default: true, // TODO(mafredri): Change default to false in a future version.
112128
ForceNew: true,
113-
Description: "A script to run before the agent is stopped.",
114-
Type: schema.TypeString,
115129
Optional: true,
130+
Description: "Allow users to login to the workspace before the agent is ready. Note that, when enabled, the agent could still be executing the startup script and the workspace in an incomplete state when logging in.",
116131
},
117132
},
118133
}

provider/agent_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ func TestAgent(t *testing.T) {
3131
hi = "test"
3232
}
3333
startup_script = "echo test"
34+
startup_script_timeout = 120
3435
troubleshooting_url = "https://example.com/troubleshoot"
3536
motd_file = "/etc/motd"
3637
shutdown_script = "echo bye bye"
38+
allow_login_before_ready = false
3739
}
3840
`,
3941
Check: func(state *terraform.State) error {
@@ -49,10 +51,12 @@ func TestAgent(t *testing.T) {
4951
"dir",
5052
"env.hi",
5153
"startup_script",
54+
"startup_script_timeout",
5255
"connection_timeout",
5356
"troubleshooting_url",
5457
"motd_file",
5558
"shutdown_script",
59+
"allow_login_before_ready",
5660
} {
5761
value := resource.Primary.Attributes[key]
5862
t.Logf("%q = %q", key, value)

0 commit comments

Comments
 (0)