|
3 | 3 | page_title: "coder_script Resource - terraform-provider-coder"
|
4 | 4 | subcategory: ""
|
5 | 5 | description: |-
|
6 |
| - Use this resource to run a script from an agent. |
| 6 | + Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. |
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # coder_script (Resource)
|
10 | 10 |
|
11 |
| -Use this resource to run a script from an agent. |
| 11 | +Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. |
12 | 12 |
|
| 13 | +## Example Usage |
13 | 14 |
|
| 15 | +```terraform |
| 16 | +data "coder_workspace" "me" {} |
| 17 | +
|
| 18 | +resource "coder_agent" "dev" { |
| 19 | + os = "linux" |
| 20 | + arch = "amd64" |
| 21 | + dir = "/workspace" |
| 22 | +} |
| 23 | +
|
| 24 | +resource "coder_script" "dotfiles" { |
| 25 | + agent_id = coder_agent.dev.agent_id |
| 26 | + display_name = "Dotfiles" |
| 27 | + icon = "/icon/dotfiles.svg" |
| 28 | + run_on_start = true |
| 29 | + script = templatefile("~/get_dotfiles.sh", { |
| 30 | + DOTFILES_URI : var.dotfiles_uri, |
| 31 | + DOTFILES_USER : var.dotfiles_user |
| 32 | + }) |
| 33 | +} |
| 34 | +
|
| 35 | +resource "coder_script" "code-server" { |
| 36 | + agent_id = coder_agent.dev.agent_id |
| 37 | + display_name = "code-server" |
| 38 | + icon = "/icon/code.svg" |
| 39 | + run_on_start = true |
| 40 | + start_blocks_login = true |
| 41 | + script = templatefile("./install-code-server.sh", { |
| 42 | + LOG_PATH : "/tmp/code-server.log" |
| 43 | + }) |
| 44 | +} |
| 45 | +
|
| 46 | +resource "coder_script" "nightly_sleep_reminder" { |
| 47 | + agent_id = coder_agent.dev.agent_id |
| 48 | + display_name = "Nightly update" |
| 49 | + icon = "/icon/database.svg" |
| 50 | + cron = "0 22 * * *" |
| 51 | + script = <<EOF |
| 52 | + #!/bin/sh |
| 53 | + echo "Running nightly update" |
| 54 | + sudo apt-get install |
| 55 | + EOF |
| 56 | +} |
| 57 | +
|
| 58 | +resource "coder_script" "shutdown" { |
| 59 | + agent_id = coder_agent.dev.id |
| 60 | + display_name = "Stop daemon server" |
| 61 | + run_on_stop = true |
| 62 | + icon = "/icons/memory.svg" |
| 63 | + script = <<EOF |
| 64 | + #!/bin/sh |
| 65 | + kill $(lsof -i :3002 -t) >/tmp/pid.log 2>&1 & |
| 66 | + EOF |
| 67 | +} |
| 68 | +``` |
14 | 69 |
|
15 | 70 | <!-- schema generated by tfplugindocs -->
|
16 | 71 | ## Schema
|
|
0 commit comments