Skip to content

Commit

Permalink
fix: improve coder_script related docs (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri authored Feb 9, 2024
1 parent 7a00ae7 commit 908ab27
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/resources/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ resource "kubernetes_pod" "dev" {
- `login_before_ready` (Boolean, Deprecated) This option defines whether or not the user can (by default) login to the workspace before it is ready. Ready means that e.g. the startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.
- `metadata` (Block List) Each "metadata" block defines a single item consisting of a key/value pair. This feature is in alpha and may break in future releases. (see [below for nested schema](#nestedblock--metadata))
- `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. The script should exit when it is done to signal that the workspace can be stopped.
- `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. This option is an alias for defining a "coder_script" resource with "run_on_stop" set to true.
- `shutdown_script_timeout` (Number, Deprecated) Time in seconds until the agent lifecycle status is marked as timed out during shutdown, this happens when the shutdown script has not completed (exited) in the given time.
- `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_behavior` (String) This option sets the behavior of the `startup_script`. When set to "blocking", the startup_script must exit before the workspace is ready. When set to "non-blocking", the startup_script may run in the background and the workspace will be ready immediately. Default is "non-blocking", although "blocking" is recommended.
- `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. This option is an alias for defining a "coder_script" resource with "run_on_start" set to true.
- `startup_script_behavior` (String) This option sets the behavior of the "startup_script". When set to "blocking", the startup_script must exit before the workspace is ready. When set to "non-blocking", the startup_script may run in the background and the workspace will be ready immediately. Default is "non-blocking", although "blocking" is recommended. This option is an alias for defining a "coder_script" resource with "start_blocks_login" set to true (blocking).
- `startup_script_timeout` (Number, Deprecated) Time in seconds until the agent lifecycle status is marked as timed out during start, 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.

Expand Down
10 changes: 5 additions & 5 deletions docs/resources/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ Use this resource to run a script from an agent.

- `agent_id` (String) The "id" property of a "coder_agent" resource to associate with.
- `display_name` (String) The display name of the script to display logs in the dashboard.
- `script` (String) The script to run.
- `script` (String) The content of the script that will be run.

### Optional

- `cron` (String) The cron schedule to run the script on. This is a cron expression.
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/<path>"`.
- `log_path` (String) The path of a file to write the logs to. If relative, it will be appended to tmp.
- `run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts.
- `run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops.
- `start_blocks_login` (Boolean) This option defines whether or not the user can (by default) login to the workspace before this script completes running on start. When enabled, users may see an incomplete workspace when logging in.
- `timeout` (Number) Time in seconds until the agent lifecycle status is marked as timed out, this happens when the script has not completed (exited) in the given time.
- `run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts. The script should exit when it is done to signal that the agent is ready.
- `run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops. The script should exit when it is done to signal that the workspace can be stopped.
- `start_blocks_login` (Boolean) This option determines whether users can log in immediately or must wait for the workspace to finish running this script upon startup. If not enabled, users may encounter an incomplete workspace when logging in. This option only sets the default, the user can still manually override the behavior.
- `timeout` (Number) Time in seconds that the script is allowed to run. If the script does not complete within this time, the script is terminated and the agent lifecycle status is marked as timed out. A value of zero (default) means no timeout.

### Read-Only

Expand Down
8 changes: 4 additions & 4 deletions provider/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func agentResource() *schema.Resource {
return &schema.Resource{
Description: "Use this resource to associate an agent.",
CreateContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
CreateContext: func(_ context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
// This should be a real authentication token!
resourceData.SetId(uuid.NewString())
err := resourceData.Set("token", uuid.NewString())
Expand Down Expand Up @@ -121,7 +121,7 @@ func agentResource() *schema.Resource {
},
"startup_script": {
ForceNew: true,
Description: "A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready.",
Description: `A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready. This option is an alias for defining a "coder_script" resource with "run_on_start" set to true.`,
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -138,7 +138,7 @@ func agentResource() *schema.Resource {
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.",
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. This option is an alias for defining a "coder_script" resource with "run_on_stop" set to true.`,
},
"shutdown_script_timeout": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -197,7 +197,7 @@ func agentResource() *schema.Resource {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "This option sets the behavior of the `startup_script`. When set to \"blocking\", the startup_script must exit before the workspace is ready. When set to \"non-blocking\", the startup_script may run in the background and the workspace will be ready immediately. Default is \"non-blocking\", although \"blocking\" is recommended.",
Description: `This option sets the behavior of the "startup_script". When set to "blocking", the startup_script must exit before the workspace is ready. When set to "non-blocking", the startup_script may run in the background and the workspace will be ready immediately. Default is "non-blocking", although "blocking" is recommended. This option is an alias for defining a "coder_script" resource with "start_blocks_login" set to true (blocking).`,
ValidateFunc: validation.StringInSlice([]string{"blocking", "non-blocking"}, false),
ConflictsWith: []string{"login_before_ready"},
},
Expand Down
14 changes: 7 additions & 7 deletions provider/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ScriptCRONParser = cron.NewParser(cron.Second | cron.Minute | cron.Hour | cr
func scriptResource() *schema.Resource {
return &schema.Resource{
Description: "Use this resource to run a script from an agent.",
CreateContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
CreateContext: func(_ context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
rd.SetId(uuid.NewString())
runOnStart, _ := rd.Get("run_on_start").(bool)
runOnStop, _ := rd.Get("run_on_stop").(bool)
Expand Down Expand Up @@ -60,14 +60,14 @@ func scriptResource() *schema.Resource {
ForceNew: true,
Type: schema.TypeString,
Required: true,
Description: "The script to run.",
Description: "The content of the script that will be run.",
},
"cron": {
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Description: "The cron schedule to run the script on. This is a cron expression.",
ValidateFunc: func(i interface{}, s string) ([]string, []error) {
ValidateFunc: func(i interface{}, _ string) ([]string, []error) {
v, ok := i.(string)
if !ok {
return []string{}, []error{fmt.Errorf("got type %T instead of string", i)}
Expand All @@ -84,28 +84,28 @@ func scriptResource() *schema.Resource {
Default: false,
ForceNew: true,
Optional: true,
Description: "This option defines whether or not the user can (by default) login to the workspace before this script completes running on start. When enabled, users may see an incomplete workspace when logging in.",
Description: "This option determines whether users can log in immediately or must wait for the workspace to finish running this script upon startup. If not enabled, users may encounter an incomplete workspace when logging in. This option only sets the default, the user can still manually override the behavior.",
},
"run_on_start": {
Type: schema.TypeBool,
Default: false,
ForceNew: true,
Optional: true,
Description: "This option defines whether or not the script should run when the agent starts.",
Description: "This option defines whether or not the script should run when the agent starts. The script should exit when it is done to signal that the agent is ready.",
},
"run_on_stop": {
Type: schema.TypeBool,
Default: false,
ForceNew: true,
Optional: true,
Description: "This option defines whether or not the script should run when the agent stops.",
Description: "This option defines whether or not the script should run when the agent stops. The script should exit when it is done to signal that the workspace can be stopped.",
},
"timeout": {
Type: schema.TypeInt,
Default: 0,
ForceNew: true,
Optional: true,
Description: "Time in seconds until the agent lifecycle status is marked as timed out, this happens when the script has not completed (exited) in the given time.",
Description: "Time in seconds that the script is allowed to run. If the script does not complete within this time, the script is terminated and the agent lifecycle status is marked as timed out. A value of zero (default) means no timeout.",
ValidateFunc: validation.IntAtLeast(1),
},
},
Expand Down

0 comments on commit 908ab27

Please sign in to comment.