Skip to content

Commit 35e6ac8

Browse files
authored
docs: add missing code examples (#249)
* coder_env code example * added coder_script example * updated coder_script description to note parallelism * short coder_external_auth example * added external auth link, make gen * fixed icon link for coder_parameter * coder_provisioner example * fixed inline links for provisioner * added coder_workspace_owner examples
1 parent 60401e6 commit 35e6ac8

File tree

15 files changed

+282
-13
lines changed

15 files changed

+282
-13
lines changed

docs/data-sources/external_auth.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@
33
page_title: "coder_external_auth Data Source - terraform-provider-coder"
44
subcategory: ""
55
description: |-
6-
Use this data source to require users to authenticate with an external service prior to workspace creation. This can be used to pre-authenticate external services in a workspace. (e.g. gcloud, gh, docker, etc)
6+
Use this data source to require users to authenticate with an external service prior to workspace creation. This can be used to pre-authenticate external services https://coder.com/docs/admin/external-auth in a workspace. (e.g. Google Cloud, Github, Docker, etc.)
77
---
88

99
# coder_external_auth (Data Source)
1010

11-
Use this data source to require users to authenticate with an external service prior to workspace creation. This can be used to pre-authenticate external services in a workspace. (e.g. gcloud, gh, docker, etc)
11+
Use this data source to require users to authenticate with an external service prior to workspace creation. This can be used to [pre-authenticate external services](https://coder.com/docs/admin/external-auth) in a workspace. (e.g. Google Cloud, Github, Docker, etc.)
1212

13+
## Example Usage
1314

15+
```terraform
16+
provider "coder" {}
17+
18+
19+
data "coder_external_auth" "github" {
20+
id = "github"
21+
}
22+
23+
data "coder_external_auth" "azure-identity" {
24+
id = "azure-identiy"
25+
optional = true
26+
}
27+
```
1428

1529
<!-- schema generated by tfplugindocs -->
1630
## Schema

docs/data-sources/parameter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ data "coder_parameter" "home_volume_size" {
145145
- `description` (String) Describe what this parameter does.
146146
- `display_name` (String) The displayed name of the parameter as it will appear in the interface.
147147
- `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds.
148-
- `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>"`.
148+
- `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>"`.
149149
- `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution!
150150
- `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option))
151151
- `order` (Number) The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order).

docs/data-sources/provisioner.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,33 @@ description: |-
1010

1111
Use this data source to get information about the Coder provisioner.
1212

13+
## Example Usage
1314

15+
```terraform
16+
provider "coder" {}
17+
18+
data "coder_provisioner" "dev" {}
19+
20+
data "coder_workspace" "dev" {}
21+
22+
resource "coder_agent" "main" {
23+
arch = data.coder_provisioner.dev.arch
24+
os = data.coder_provisioner.dev.os
25+
dir = "/workspace"
26+
display_apps {
27+
vscode = true
28+
vscode_insiders = false
29+
web_terminal = true
30+
ssh_helper = false
31+
}
32+
}
33+
```
1434

1535
<!-- schema generated by tfplugindocs -->
1636
## Schema
1737

1838
### Read-Only
1939

20-
- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants).
40+
- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)).
2141
- `id` (String) The ID of this resource.
22-
- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants).
42+
- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)).

docs/data-sources/workspace_owner.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,38 @@ description: |-
1010

1111
Use this data source to fetch information about the workspace owner.
1212

13+
## Example Usage
1314

15+
```terraform
16+
provider "coder" {}
17+
18+
data "coder_workspace" "me" {}
19+
20+
data "coder_workspace_owner" "me" {}
21+
22+
resource "coder_agent" "dev" {
23+
arch = "amd64"
24+
os = "linux"
25+
dir = local.repo_dir
26+
env = {
27+
OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token,
28+
}
29+
}
30+
31+
# Add git credentials from coder_workspace_owner
32+
resource "coder_env" "git_author_name" {
33+
agent_id = coder_agent.agent_id
34+
name = "GIT_AUTHOR_NAME"
35+
value = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
36+
}
37+
38+
resource "coder_env" "git_author_email" {
39+
agent_id = var.agent_id
40+
name = "GIT_AUTHOR_EMAIL"
41+
value = data.coder_workspace_owner.me.email
42+
count = data.coder_workspace_owner.me.email != "" ? 1 : 0
43+
}
44+
```
1445

1546
<!-- schema generated by tfplugindocs -->
1647
## Schema

docs/resources/env.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,29 @@ description: |-
1010

1111
Use this resource to set an environment variable in a workspace. Note that this resource cannot be used to overwrite existing environment variables set on the "coder_agent" resource.
1212

13-
13+
## Example Usage
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_env" "welcome_message" {
25+
agent_id = coder_agent.dev.id
26+
name = "WELCOME_MESSAGE"
27+
value = "Welcome to your Coder workspace!"
28+
}
29+
30+
resource "coder_env" "internal_api_url" {
31+
agent_id = coder_agent.dev.id
32+
name = "INTERNAL_API_URL"
33+
value = "https://api.internal.company.com/v1"
34+
}
35+
```
1436

1537
<!-- schema generated by tfplugindocs -->
1638
## Schema

docs/resources/script.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,69 @@
33
page_title: "coder_script Resource - terraform-provider-coder"
44
subcategory: ""
55
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.
77
---
88

99
# coder_script (Resource)
1010

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.
1212

13+
## Example Usage
1314

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+
```
1469

1570
<!-- schema generated by tfplugindocs -->
1671
## Schema
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "coder" {}
2+
3+
4+
data "coder_external_auth" "github" {
5+
id = "github"
6+
}
7+
8+
data "coder_external_auth" "azure-identity" {
9+
id = "azure-identiy"
10+
optional = true
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
provider "coder" {}
2+
3+
data "coder_provisioner" "dev" {}
4+
5+
data "coder_workspace" "dev" {}
6+
7+
resource "coder_agent" "main" {
8+
arch = data.coder_provisioner.dev.arch
9+
os = data.coder_provisioner.dev.os
10+
dir = "/workspace"
11+
display_apps {
12+
vscode = true
13+
vscode_insiders = false
14+
web_terminal = true
15+
ssh_helper = false
16+
}
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
provider "coder" {}
2+
3+
data "coder_workspace" "me" {}
4+
5+
data "coder_workspace_owner" "me" {}
6+
7+
resource "coder_agent" "dev" {
8+
arch = "amd64"
9+
os = "linux"
10+
dir = local.repo_dir
11+
env = {
12+
OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token,
13+
}
14+
}
15+
16+
# Add git credentials from coder_workspace_owner
17+
resource "coder_env" "git_author_name" {
18+
agent_id = coder_agent.agent_id
19+
name = "GIT_AUTHOR_NAME"
20+
value = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
21+
}
22+
23+
resource "coder_env" "git_author_email" {
24+
agent_id = var.agent_id
25+
name = "GIT_AUTHOR_EMAIL"
26+
value = data.coder_workspace_owner.me.email
27+
count = data.coder_workspace_owner.me.email != "" ? 1 : 0
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
data "coder_workspace" "me" {}
2+
3+
resource "coder_agent" "dev" {
4+
os = "linux"
5+
arch = "amd64"
6+
dir = "/workspace"
7+
}
8+
9+
resource "coder_env" "welcome_message" {
10+
agent_id = coder_agent.dev.id
11+
name = "WELCOME_MESSAGE"
12+
value = "Welcome to your Coder workspace!"
13+
}
14+
15+
resource "coder_env" "internal_api_url" {
16+
agent_id = coder_agent.dev.id
17+
name = "INTERNAL_API_URL"
18+
value = "https://api.internal.company.com/v1"
19+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy