Skip to content

Commit 0385749

Browse files
authored
feat: Add startup_script_timeout and delay_login_until_ready (#84)
Ref: coder/coder#5749
1 parent bb057f8 commit 0385749

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
@@ -48,11 +48,13 @@ resource "kubernetes_pod" "dev" {
4848

4949
- `auth` (String) The authentication type the agent will use. Must be one of: "token", "google-instance-identity", "aws-instance-identity", "azure-instance-identity".
5050
- `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.
51+
- `delay_login_until_ready` (Boolean) This option defines whether or not user logins to the workspace agent are delayed until the agent is ready. When disabled, users may see an incomplete workspace upon logging in.
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.
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.",
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+
"delay_login_until_ready": {
126+
Type: schema.TypeBool,
127+
Default: false, // Change default value to true in a future release.
112128
ForceNew: true,
113-
Description: "A script to run before the agent is stopped.",
114-
Type: schema.TypeString,
115129
Optional: true,
130+
Description: "This option defines whether or not user logins to the workspace agent are delayed until the agent is ready. When disabled, users may see an incomplete workspace upon 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+
delay_login_until_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+
"delay_login_until_ready",
5660
} {
5761
value := resource.Primary.Attributes[key]
5862
t.Logf("%q = %q", key, value)

0 commit comments

Comments
 (0)