Skip to content

Commit 3bfb793

Browse files
docs: add examples for all resources & data sources (#78)
1 parent dfa7472 commit 3bfb793

File tree

20 files changed

+408
-18
lines changed

20 files changed

+408
-18
lines changed

Diff for: docs/data-sources/group.md

+31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,38 @@ description: |-
1010

1111
An existing group on the Coder deployment.
1212

13+
## Example Usage
1314

15+
```terraform
16+
// Get a group on the provider default organization by `id`
17+
data "coderd_group" "employees" {
18+
id = "abcd-efg-hijk"
19+
}
20+
21+
// Get a group on the provider default organization by `name` + `organization_id`
22+
data "coderd_group" "bosses" {
23+
name = "bosses"
24+
}
25+
26+
// Use them to apply ACL to a template
27+
resource "coderd_template" "example" {
28+
name = "example-template"
29+
versions = [/* ... */]
30+
acl = {
31+
groups = [
32+
{
33+
id = data.coderd_group.employees.id
34+
role = "use"
35+
},
36+
{
37+
id = data.coderd_group.bosses.id
38+
role = "admin"
39+
}
40+
]
41+
users = []
42+
}
43+
}
44+
```
1445

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

Diff for: docs/data-sources/organization.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,30 @@ An existing organization on the Coder deployment.
1515
~> **Warning**
1616
This data source is only compatible with Coder version [2.13.0](https://github.com/coder/coder/releases/tag/v2.13.0) and later.
1717

18-
18+
## Example Usage
19+
20+
```terraform
21+
// Get the default (first) organization for the coder deployment
22+
data "coderd_organization" "default" {
23+
is_default = true
24+
}
25+
26+
// Get another organization by `id`
27+
data "coderd_organization" "example" {
28+
id = "abcd-efg-hijk"
29+
}
30+
31+
// Or get by name
32+
data "coderd_organization" "example2" {
33+
name = "example-organization-2"
34+
}
35+
36+
// Create a group on a specific organization
37+
resource "coderd_group" "example" {
38+
name = "example-group"
39+
organization_id = data.coderd_organization.example.id
40+
}
41+
```
1942

2043
<!-- schema generated by tfplugindocs -->
2144
## Schema

Diff for: docs/data-sources/template.md

+24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,31 @@ description: |-
1010

1111
An existing template on the Coder deployment.
1212

13+
## Example Usage
1314

15+
```terraform
16+
// Get a template on the provider's default organization by `id`
17+
data "coderd_template" "ubuntu-main" {
18+
id = "abcd-efg-hijk"
19+
}
20+
21+
// Get a template on the provider's default organization by `name`
22+
data "coderd_template" "windows-main" {
23+
name = "windows-main"
24+
}
25+
26+
// Manage a template resource with the same permissions & settings as an existing template
27+
resource "coderd_template" "debian-main" {
28+
name = "debian-main"
29+
versions = [/* ... */]
30+
acl = data.coderd_template.ubuntu-main.acl
31+
allow_user_auto_start = data.coderd_template.ubuntu-main.allow_user_auto_start
32+
auto_start_permitted_days_of_week = data.coderd_template.ubuntu-main.auto_start_permitted_days_of_week
33+
allow_user_auto_stop = data.coderd_template.ubuntu-main.allow_user_auto_stop
34+
auto_stop_requirement = data.coderd_template.ubuntu-main.auto_stop_requirement
35+
allow_user_cancel_workspace_jobs = data.coderd_template.ubuntu-main.allow_user_cancel_workspace_jobs
36+
}
37+
```
1438

1539
<!-- schema generated by tfplugindocs -->
1640
## Schema

Diff for: docs/data-sources/user.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,29 @@ description: |-
1010

1111
An existing user on the Coder deployment
1212

13-
13+
## Example Usage
14+
15+
```terraform
16+
// Get a user on the Coder deployment by `id`
17+
data "coderd_user" "manager" {
18+
id = "abcd-efg-hijk"
19+
}
20+
21+
// Get a user on the Coder deployment by `username`
22+
data "coderd_user" "admin" {
23+
username = "admin"
24+
}
25+
26+
27+
// Use them to create a group
28+
resource "coderd_group" "bosses" {
29+
name = "group"
30+
members = [
31+
data.coderd_user.admin.id,
32+
data.coderd_user.manager.id
33+
]
34+
}
35+
```
1436

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

Diff for: docs/index.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,87 @@
33
page_title: "coderd Provider"
44
subcategory: ""
55
description: |-
6+
The coderd provider can be used to manage resources on a Coder deployment. The provider exposes resources and data sources for users, groups, templates, and workspace proxies.
67
~> Warning
78
This provider is only compatible with Coder version 2.10.1 https://github.com/coder/coder/releases/tag/v2.10.1 and later.
89
---
910

1011
# coderd Provider
1112

13+
The coderd provider can be used to manage resources on a Coder deployment. The provider exposes resources and data sources for users, groups, templates, and workspace proxies.
14+
1215
~> **Warning**
1316
This provider is only compatible with Coder version [2.10.1](https://github.com/coder/coder/releases/tag/v2.10.1) and later.
1417

18+
## Example Usage
19+
20+
```terraform
21+
terraform {
22+
required_providers {
23+
coderd = {
24+
source = "coder/coderd"
25+
}
26+
}
27+
}
28+
29+
provider "coderd" {
30+
url = "coder.example.com"
31+
token = "****"
32+
}
33+
34+
35+
data "coderd_organization" "default" {
36+
is_default = true
37+
}
38+
39+
data "coderd_user" "admin" {
40+
username = "admin"
41+
}
42+
43+
resource "coderd_user" "manager" {
44+
username = "Manager"
45+
46+
}
47+
48+
resource "coderd_group" "bosses" {
49+
name = "group"
50+
members = [
51+
data.coderd_user.admin.id,
52+
resource.coderd_user.manager.id
53+
]
54+
}
1555
56+
resource "coderd_template" "example" {
57+
name = "example-template"
58+
versions = [{
59+
directory = "./example-template"
60+
active = true
61+
tf_vars = [{
62+
name = "image_id"
63+
value = "ami-12345678"
64+
}]
65+
# Version names can be randomly generated if null/omitted
66+
}]
67+
acl = {
68+
groups = [{
69+
id = data.coderd_organization.default.id
70+
role = "use"
71+
},
72+
{
73+
id = resource.coderd_group.bosses.id
74+
role = "admin"
75+
}]
76+
users = []
77+
}
78+
allow_user_cancel_workspace_jobs = false
79+
}
80+
```
1681

1782
<!-- schema generated by tfplugindocs -->
1883
## Schema
1984

2085
### Optional
2186

2287
- `default_organization_id` (String) Default organization ID to use when creating resources. Defaults to the first organization the token has access to.
23-
- `token` (String) API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to $CODER_SESSION_TOKEN.
24-
- `url` (String) URL to the Coder deployment. Defaults to $CODER_URL.
88+
- `token` (String) API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to `$CODER_SESSION_TOKEN`.
89+
- `url` (String) URL to the Coder deployment. Defaults to `$CODER_URL`.

Diff for: docs/resources/group.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
page_title: "coderd_group Resource - terraform-provider-coderd"
44
subcategory: ""
55
description: |-
6-
A group on the Coder deployment. If you want to have a group resource with unmanaged members, but still want to read the members in Terraform, use the data.coderd_group data source. Creating groups requires an Enterprise license.
6+
A group on the Coder deployment.
7+
Creating groups requires an Enterprise license.
78
---
89

910
# coderd_group (Resource)
1011

11-
A group on the Coder deployment. If you want to have a group resource with unmanaged members, but still want to read the members in Terraform, use the `data.coderd_group` data source. Creating groups requires an Enterprise license.
12+
A group on the Coder deployment.
13+
14+
Creating groups requires an Enterprise license.
1215

1316
## Example Usage
1417

@@ -49,7 +52,7 @@ resource "coderd_group" "group1" {
4952

5053
- `avatar_url` (String) The URL of the group's avatar.
5154
- `display_name` (String) The display name of the group. Defaults to the group name.
52-
- `members` (Set of String) Members of the group, by ID. If null, members will not be added or removed by Terraform.
55+
- `members` (Set of String) Members of the group, by ID. If null, members will not be added or removed by Terraform. To have a group resource with unmanaged members, but be able to read the members in Terraform, use `data.coderd_group`
5356
- `organization_id` (String) The organization ID that the group belongs to. Defaults to the provider default organization ID.
5457
- `quota_allowance` (Number) The number of quota credits to allocate to each user in the group.
5558

Diff for: docs/resources/template.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ resource "coderd_template" "ubuntu-main" {
4242
directory = "./staging-template"
4343
}
4444
]
45+
acl = {
46+
users = [{
47+
id = coderd_user.coder1.id
48+
role = "admin"
49+
}]
50+
}
4551
}
4652
```
4753

@@ -55,23 +61,23 @@ resource "coderd_template" "ubuntu-main" {
5561

5662
### Optional
5763

58-
- `acl` (Attributes) (Enterprise) Access control list for the template. If null, ACL policies will not be added or removed by Terraform. (see [below for nested schema](#nestedatt--acl))
64+
- `acl` (Attributes) (Enterprise) Access control list for the template. If null, ACL policies will not be added, removed, or read by Terraform. (see [below for nested schema](#nestedatt--acl))
5965
- `activity_bump_ms` (Number) The activity bump duration for all workspaces created from this template, in milliseconds. Defaults to one hour.
6066
- `allow_user_auto_start` (Boolean) (Enterprise) Whether users can auto-start workspaces created from this template. Defaults to true.
6167
- `allow_user_auto_stop` (Boolean) (Enterprise) Whether users can auto-start workspaces created from this template. Defaults to true.
6268
- `allow_user_cancel_workspace_jobs` (Boolean) Whether users can cancel in-progress workspace jobs using this template. Defaults to true.
6369
- `auto_start_permitted_days_of_week` (Set of String) (Enterprise) List of days of the week in which autostart is allowed to happen, for all workspaces created from this template. Defaults to all days. If no days are specified, autostart is not allowed.
6470
- `auto_stop_requirement` (Attributes) (Enterprise) The auto-stop requirement for all workspaces created from this template. (see [below for nested schema](#nestedatt--auto_stop_requirement))
6571
- `default_ttl_ms` (Number) The default time-to-live for all workspaces created from this template, in milliseconds.
66-
- `deprecation_message` (String) If set, the template will be marked as deprecated and users will be blocked from creating new workspaces from it.
72+
- `deprecation_message` (String) If set, the template will be marked as deprecated with the provided message and users will be blocked from creating new workspaces from it.
6773
- `description` (String) A description of the template.
6874
- `display_name` (String) The display name of the template. Defaults to the template name.
6975
- `failure_ttl_ms` (Number) (Enterprise) The max lifetime before Coder stops all resources for failed workspaces created from this template, in milliseconds.
7076
- `icon` (String) Relative path or external URL that specifes an icon to be displayed in the dashboard.
7177
- `organization_id` (String) The ID of the organization. Defaults to the provider's default organization
7278
- `require_active_version` (Boolean) (Enterprise) Whether workspaces must be created from the active version of this template. Defaults to false.
7379
- `time_til_dormant_autodelete_ms` (Number) (Enterprise) The max lifetime before Coder permanently deletes dormant workspaces created from this template.
74-
- `time_til_dormant_ms` (Number) Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.
80+
- `time_til_dormant_ms` (Number) (Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.
7581

7682
### Read-Only
7783

Diff for: docs/resources/user.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ resource "coderd_user" "audit" {
3939
resource "coderd_user" "admin" {
4040
username = "admin"
4141
suspended = true
42+
4243
}
4344
```
4445

Diff for: docs/resources/workspace_proxy.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,38 @@ description: |-
1010

1111
A Workspace Proxy for the Coder deployment.
1212

13-
13+
## Example Usage
14+
15+
```terraform
16+
resource "coderd_workspace_proxy" "sydney-wsp" {
17+
name = "sydney-wsp"
18+
display_name = "Australia (Sydney)"
19+
icon = "/emojis/1f1e6-1f1fa.png"
20+
}
21+
22+
resource "kubernetes_deployment" "syd_wsproxy" {
23+
metadata { /* ... */ }
24+
spec {
25+
template {
26+
metadata { /* ... */ }
27+
spec {
28+
container {
29+
name = "syd-wsp"
30+
image = "ghcr.io/coder/coder:latest"
31+
args = ["wsproxy", "server"]
32+
env {
33+
name = "CODER_PROXY_SESSION_TOKEN"
34+
value = coderd_workspace_proxy.sydney-wsp.session_token
35+
}
36+
/* ... */
37+
}
38+
/* ... */
39+
}
40+
}
41+
/* ... */
42+
}
43+
}
44+
```
1445

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

Diff for: examples/data-sources/coderd_group/data-source.tf

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Get a group on the provider default organization by `id`
2+
data "coderd_group" "employees" {
3+
id = "abcd-efg-hijk"
4+
}
5+
6+
// Get a group on the provider default organization by `name` + `organization_id`
7+
data "coderd_group" "bosses" {
8+
name = "bosses"
9+
}
10+
11+
// Use them to apply ACL to a template
12+
resource "coderd_template" "example" {
13+
name = "example-template"
14+
versions = [/* ... */]
15+
acl = {
16+
groups = [
17+
{
18+
id = data.coderd_group.employees.id
19+
role = "use"
20+
},
21+
{
22+
id = data.coderd_group.bosses.id
23+
role = "admin"
24+
}
25+
]
26+
users = []
27+
}
28+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Get the default (first) organization for the coder deployment
2+
data "coderd_organization" "default" {
3+
is_default = true
4+
}
5+
6+
// Get another organization by `id`
7+
data "coderd_organization" "example" {
8+
id = "abcd-efg-hijk"
9+
}
10+
11+
// Or get by name
12+
data "coderd_organization" "example2" {
13+
name = "example-organization-2"
14+
}
15+
16+
// Create a group on a specific organization
17+
resource "coderd_group" "example" {
18+
name = "example-group"
19+
organization_id = data.coderd_organization.example.id
20+
}

0 commit comments

Comments
 (0)