Skip to content

feat: Add startup_script_timeout and delay_login_until_ready #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
6 changes: 4 additions & 2 deletions docs/resources/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ resource "kubernetes_pod" "dev" {

- `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.
- `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.
- `dir` (String) The starting directory when a user creates a shell session. Defaults to $HOME.
- `env` (Map of String) A mapping of environment variables to set inside the workspace.
- `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.
- `shutdown_script` (String) A script to run before the agent is stopped.
- `startup_script` (String) A script to run after the agent starts.
- `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.
- `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.
- `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.
- `troubleshooting_url` (String) A URL to a document with instructions for troubleshooting problems with the agent.

### Read-Only
Expand Down
23 changes: 19 additions & 4 deletions provider/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,24 @@ func agentResource() *schema.Resource {
},
"startup_script": {
ForceNew: true,
Description: "A script to run after the agent starts.",
Description: "A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready.",
Type: schema.TypeString,
Optional: true,
},
"startup_script_timeout": {
Type: schema.TypeInt,
Default: 300,
ForceNew: true,
Optional: true,
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.",
ValidateFunc: validation.IntAtLeast(1),
},
"shutdown_script": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
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.",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated description here, I considered commenting it out or adding (NOT YET IMPLEMENTED.), but we'll likely do this soon after we get the startup script changes in.

},
"token": {
ForceNew: true,
Sensitive: true,
Expand Down Expand Up @@ -108,11 +122,12 @@ func agentResource() *schema.Resource {
Optional: true,
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.",
},
"shutdown_script": {
"delay_login_until_ready": {
Type: schema.TypeBool,
Default: false, // Change default value to true in a future release.
ForceNew: true,
Description: "A script to run before the agent is stopped.",
Type: schema.TypeString,
Optional: true,
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.",
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions provider/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ func TestAgent(t *testing.T) {
hi = "test"
}
startup_script = "echo test"
startup_script_timeout = 120
troubleshooting_url = "https://example.com/troubleshoot"
motd_file = "/etc/motd"
shutdown_script = "echo bye bye"
delay_login_until_ready = false
}
`,
Check: func(state *terraform.State) error {
Expand All @@ -49,10 +51,12 @@ func TestAgent(t *testing.T) {
"dir",
"env.hi",
"startup_script",
"startup_script_timeout",
"connection_timeout",
"troubleshooting_url",
"motd_file",
"shutdown_script",
"delay_login_until_ready",
} {
value := resource.Primary.Attributes[key]
t.Logf("%q = %q", key, value)
Expand Down