diff --git a/docs/resources/agent.md b/docs/resources/agent.md index a064585c..1415cc04 100644 --- a/docs/resources/agent.md +++ b/docs/resources/agent.md @@ -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 diff --git a/provider/agent.go b/provider/agent.go index 0216d8dd..5d4af4f1 100644 --- a/provider/agent.go +++ b/provider/agent.go @@ -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.", + }, "token": { ForceNew: true, Sensitive: true, @@ -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.", }, }, } diff --git a/provider/agent_test.go b/provider/agent_test.go index ae3be7af..9efa15bf 100644 --- a/provider/agent_test.go +++ b/provider/agent_test.go @@ -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 { @@ -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)