Skip to content

Commit 908ab27

Browse files
authored
fix: improve coder_script related docs (#191)
1 parent 7a00ae7 commit 908ab27

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

docs/resources/agent.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ resource "kubernetes_pod" "dev" {
7979
- `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.
8080
- `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))
8181
- `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.
82-
- `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.
82+
- `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.
8383
- `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.
84-
- `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.
85-
- `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.
84+
- `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.
85+
- `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).
8686
- `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.
8787
- `troubleshooting_url` (String) A URL to a document with instructions for troubleshooting problems with the agent.
8888

docs/resources/script.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ Use this resource to run a script from an agent.
1919

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

2424
### Optional
2525

2626
- `cron` (String) The cron schedule to run the script on. This is a cron expression.
2727
- `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>"`.
2828
- `log_path` (String) The path of a file to write the logs to. If relative, it will be appended to tmp.
29-
- `run_on_start` (Boolean) This option defines whether or not the script should run when the agent starts.
30-
- `run_on_stop` (Boolean) This option defines whether or not the script should run when the agent stops.
31-
- `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.
32-
- `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.
29+
- `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.
30+
- `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.
31+
- `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.
32+
- `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.
3333

3434
### Read-Only
3535

provider/agent.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func agentResource() *schema.Resource {
1818
return &schema.Resource{
1919
Description: "Use this resource to associate an agent.",
20-
CreateContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
20+
CreateContext: func(_ context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics {
2121
// This should be a real authentication token!
2222
resourceData.SetId(uuid.NewString())
2323
err := resourceData.Set("token", uuid.NewString())
@@ -121,7 +121,7 @@ func agentResource() *schema.Resource {
121121
},
122122
"startup_script": {
123123
ForceNew: true,
124-
Description: "A script to run after the agent starts. The script should exit when it is done to signal that the agent is ready.",
124+
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.`,
125125
Type: schema.TypeString,
126126
Optional: true,
127127
},
@@ -138,7 +138,7 @@ func agentResource() *schema.Resource {
138138
Type: schema.TypeString,
139139
ForceNew: true,
140140
Optional: true,
141-
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.",
141+
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.`,
142142
},
143143
"shutdown_script_timeout": {
144144
Type: schema.TypeInt,
@@ -197,7 +197,7 @@ func agentResource() *schema.Resource {
197197
Type: schema.TypeString,
198198
ForceNew: true,
199199
Optional: true,
200-
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.",
200+
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).`,
201201
ValidateFunc: validation.StringInSlice([]string{"blocking", "non-blocking"}, false),
202202
ConflictsWith: []string{"login_before_ready"},
203203
},

provider/script.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var ScriptCRONParser = cron.NewParser(cron.Second | cron.Minute | cron.Hour | cr
1616
func scriptResource() *schema.Resource {
1717
return &schema.Resource{
1818
Description: "Use this resource to run a script from an agent.",
19-
CreateContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
19+
CreateContext: func(_ context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
2020
rd.SetId(uuid.NewString())
2121
runOnStart, _ := rd.Get("run_on_start").(bool)
2222
runOnStop, _ := rd.Get("run_on_stop").(bool)
@@ -60,14 +60,14 @@ func scriptResource() *schema.Resource {
6060
ForceNew: true,
6161
Type: schema.TypeString,
6262
Required: true,
63-
Description: "The script to run.",
63+
Description: "The content of the script that will be run.",
6464
},
6565
"cron": {
6666
ForceNew: true,
6767
Type: schema.TypeString,
6868
Optional: true,
6969
Description: "The cron schedule to run the script on. This is a cron expression.",
70-
ValidateFunc: func(i interface{}, s string) ([]string, []error) {
70+
ValidateFunc: func(i interface{}, _ string) ([]string, []error) {
7171
v, ok := i.(string)
7272
if !ok {
7373
return []string{}, []error{fmt.Errorf("got type %T instead of string", i)}
@@ -84,28 +84,28 @@ func scriptResource() *schema.Resource {
8484
Default: false,
8585
ForceNew: true,
8686
Optional: true,
87-
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.",
87+
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.",
8888
},
8989
"run_on_start": {
9090
Type: schema.TypeBool,
9191
Default: false,
9292
ForceNew: true,
9393
Optional: true,
94-
Description: "This option defines whether or not the script should run when the agent starts.",
94+
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.",
9595
},
9696
"run_on_stop": {
9797
Type: schema.TypeBool,
9898
Default: false,
9999
ForceNew: true,
100100
Optional: true,
101-
Description: "This option defines whether or not the script should run when the agent stops.",
101+
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.",
102102
},
103103
"timeout": {
104104
Type: schema.TypeInt,
105105
Default: 0,
106106
ForceNew: true,
107107
Optional: true,
108-
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.",
108+
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.",
109109
ValidateFunc: validation.IntAtLeast(1),
110110
},
111111
},

0 commit comments

Comments
 (0)