--- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "coder_script Resource - terraform-provider-coder" subcategory: "" description: |- Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. --- # coder_script (Resource) Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. ## Example Usage ```terraform data "coder_workspace" "me" {} resource "coder_agent" "dev" { os = "linux" arch = "amd64" dir = "/workspace" } resource "coder_script" "dotfiles" { agent_id = coder_agent.dev.id display_name = "Dotfiles" icon = "/icon/dotfiles.svg" run_on_start = true script = templatefile("~/get_dotfiles.sh", { DOTFILES_URI : var.dotfiles_uri, DOTFILES_USER : var.dotfiles_user }) } resource "coder_script" "code-server" { agent_id = coder_agent.dev.id display_name = "code-server" icon = "/icon/code.svg" run_on_start = true start_blocks_login = true script = templatefile("./install-code-server.sh", { LOG_PATH : "/tmp/code-server.log" }) } resource "coder_script" "nightly_update" { agent_id = coder_agent.dev.id display_name = "Nightly update" icon = "/icon/database.svg" cron = "0 0 22 * * *" # Run at 22:00 (10 PM) every day script = </tmp/pid.log 2>&1 & EOF } ``` ## Schema ### Required - `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 content of the script that will be run. ### Optional - `cron` (String) The cron schedule to run the script on. This uses a 6-field cron expression format: `seconds minutes hours day-of-month month day-of-week`. Note that this differs from the standard Unix 5-field format by including seconds as the first field. Examples: `"0 0 22 * * *"` (daily at 10 PM), `"0 */5 * * * *"` (every 5 minutes), `"30 0 9 * * 1-5"` (weekdays at 9:30 AM). - `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/"`. - `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. 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 - `id` (String) The ID of this resource.