Skip to content

Commit

Permalink
docs: add examples for all resources & data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanndickson committed Aug 21, 2024
1 parent dfa7472 commit 43b6d91
Show file tree
Hide file tree
Showing 20 changed files with 383 additions and 17 deletions.
31 changes: 31 additions & 0 deletions docs/data-sources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,38 @@ description: |-

An existing group on the Coder deployment.

## Example Usage

```terraform
// Get a group on the provider default organization by `id`
data "coderd_group" "employees" {
id = "abcd-efg-hijk"
}
// Get a group on the provider default organization by `name` + `organization_id`
data "coderd_group" "bosses" {
name = "bosses"
}
// Use them to apply ACL to a template
resource "coderd_template" "example" {
name = "example-template"
versions = [/* ... */]
acl = {
groups = [
{
id = data.coderd_group.employees.id
role = "use"
},
{
id = data.coderd_group.bosses.id
role = "admin"
}
]
users = []
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
24 changes: 23 additions & 1 deletion docs/data-sources/organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,29 @@ An existing organization on the Coder deployment.
~> **Warning**
This data source is only compatible with Coder version [2.13.0](https://github.com/coder/coder/releases/tag/v2.13.0) and later.


## Example Usage

```terraform
// Get the default (first) organization for the coder deployment
data "coderd_organization" "default" {
is_default = true
}
// Get another organization by `id`
data "coderd_organization" "example" {
id = "abcd-efg-hijk"
}
data "coderd_organization" "example2" {
name = "example-organization-2"
}
// Create a group on a specific organization
resource "coderd_group" "example" {
name = "example-group"
organization_id = data.coderd_organization.default.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
14 changes: 13 additions & 1 deletion docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ description: |-

An existing template on the Coder deployment.


## Example Usage

```terraform
// Get a template on the provider's default organization by `id`
data "coderd_template" "example-template" {
id = "abcd-efg-hijk"
}
// Get a template on the provider's default organization by `name`
data "coderd_template" "example-template2" {
name = "example-template-2"
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
24 changes: 23 additions & 1 deletion docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,29 @@ description: |-

An existing user on the Coder deployment


## Example Usage

```terraform
// Get a user on the Coder deployment by `id`
data "coderd_user" "manager" {
id = "abcd-efg-hijk"
}
// Get a user on the Coder deployment by `username`
data "coderd_user" "admin" {
username = "admin"
}
// Use them to create a group
resource "coderd_group" "bosses" {
name = "group"
members = [
data.coderd_user.admin.id,
data.coderd_user.manager.id
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
70 changes: 68 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,88 @@
page_title: "coderd Provider"
subcategory: ""
description: |-
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.
~> Warning
This provider is only compatible with Coder version 2.10.1 https://github.com/coder/coder/releases/tag/v2.10.1 and later.
---

# coderd Provider

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.

~> **Warning**
This provider is only compatible with Coder version [2.10.1](https://github.com/coder/coder/releases/tag/v2.10.1) and later.

## Example Usage

```terraform
terraform {
required_providers {
coderd = {
source = "coder/coderd"
}
}
}
provider "coderd" {
# `token` and `url` can be populated from environment variables.
# `default_organization_id` can be populated using
# the first organization the session token has access to.
}
data "coderd_organization" "default" {
is_default = true
}
data "coderd_user" "admin" {
username = "admin"
}
resource "coderd_user" "manager" {
username = "Manager"
email = "[email protected]"
}
resource "coderd_group" "bosses" {
name = "group"
members = [
data.coderd_user.admin.id,
resource.coderd_user.manager.id
]
}
resource "coderd_template" "example" {
name = "example-template"
versions = [{
directory = "./example-template"
active = true
tf_vars = [{
name = "image_id"
value = "ami-12345678"
}]
# Version names can be randomly generated if null/omitted
}]
acl = {
groups = [{
id = data.coderd_organization.default.id
role = "use"
},
{
id = resource.coderd_group.bosses.id
role = "admin"
}]
users = []
}
allow_user_cancel_workspace_jobs = false
}
```

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

### Optional

- `default_organization_id` (String) Default organization ID to use when creating resources. Defaults to the first organization the token has access to.
- `token` (String) API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to $CODER_SESSION_TOKEN.
- `url` (String) URL to the Coder deployment. Defaults to $CODER_URL.
- `token` (String) API token for communicating with the deployment. Most resource types require elevated permissions. Defaults to `$CODER_SESSION_TOKEN`.
- `url` (String) URL to the Coder deployment. Defaults to `$CODER_URL`.
7 changes: 5 additions & 2 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
page_title: "coderd_group Resource - terraform-provider-coderd"
subcategory: ""
description: |-
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.
A group on the Coder deployment.
To have a group resource with unmanaged members, but be able to read the members in Terraform, use the data.coderd_group data source. Creating groups requires an Enterprise license.
---

# coderd_group (Resource)

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.
A group on the Coder deployment.

To have a group resource with unmanaged members, but be able to read the members in Terraform, use the `data.coderd_group` data source. Creating groups requires an Enterprise license.

## Example Usage

Expand Down
12 changes: 9 additions & 3 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ resource "coderd_template" "ubuntu-main" {
directory = "./staging-template"
}
]
acl = {
users = [{
id = coderd_user.coder1.id
role = "admin"
}]
}
}
```

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

### Optional

- `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))
- `acl` (Attributes) (Enterprise) Access control list for the template. If null, ACL policies will not be added, removed, or inspected by Terraform. (see [below for nested schema](#nestedatt--acl))
- `activity_bump_ms` (Number) The activity bump duration for all workspaces created from this template, in milliseconds. Defaults to one hour.
- `allow_user_auto_start` (Boolean) (Enterprise) Whether users can auto-start workspaces created from this template. Defaults to true.
- `allow_user_auto_stop` (Boolean) (Enterprise) Whether users can auto-start workspaces created from this template. Defaults to true.
- `allow_user_cancel_workspace_jobs` (Boolean) Whether users can cancel in-progress workspace jobs using this template. Defaults to true.
- `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.
- `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))
- `default_ttl_ms` (Number) The default time-to-live for all workspaces created from this template, in milliseconds.
- `deprecation_message` (String) If set, the template will be marked as deprecated and users will be blocked from creating new workspaces from it.
- `deprecation_message` (String) If set, the template will be marked as deprecated and users will be blocked from creating new workspaces from it. The provided message will be displayed.
- `description` (String) A description of the template.
- `display_name` (String) The display name of the template. Defaults to the template name.
- `failure_ttl_ms` (Number) (Enterprise) The max lifetime before Coder stops all resources for failed workspaces created from this template, in milliseconds.
- `icon` (String) Relative path or external URL that specifes an icon to be displayed in the dashboard.
- `organization_id` (String) The ID of the organization. Defaults to the provider's default organization
- `require_active_version` (Boolean) (Enterprise) Whether workspaces must be created from the active version of this template. Defaults to false.
- `time_til_dormant_autodelete_ms` (Number) (Enterprise) The max lifetime before Coder permanently deletes dormant workspaces created from this template.
- `time_til_dormant_ms` (Number) Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.
- `time_til_dormant_ms` (Number) (Enterprise) The max lifetime before Coder locks inactive workspaces created from this template, in milliseconds.

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ resource "coderd_user" "audit" {
resource "coderd_user" "admin" {
username = "admin"
suspended = true
email = "[email protected]"
}
```

Expand Down
33 changes: 32 additions & 1 deletion docs/resources/workspace_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,38 @@ description: |-

A Workspace Proxy for the Coder deployment.


## Example Usage

```terraform
resource "coderd_workspace_proxy" "sydney-wsp" {
name = "sydney-wsp"
display_name = "Australia (Sydney)"
icon = "/emojis/1f1e6-1f1fa.png"
}
resource "kubernetes_deployment" "syd_wsproxy" {
metadata { /* ... */ }
spec {
template {
metadata { /* ... */ }
spec {
container {
name = "syd-wsp"
image = "ghcr.io/coder/coder:latest"
args = ["wsproxy", "server"]
env {
name = "CODER_PROXY_SESSION_TOKEN"
value = coderd_workspace_proxy.sydney-wsp.session_token
}
/* ... */
}
/* ... */
}
}
/* ... */
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
28 changes: 28 additions & 0 deletions examples/data-sources/coderd_group/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Get a group on the provider default organization by `id`
data "coderd_group" "employees" {
id = "abcd-efg-hijk"
}

// Get a group on the provider default organization by `name` + `organization_id`
data "coderd_group" "bosses" {
name = "bosses"
}

// Use them to apply ACL to a template
resource "coderd_template" "example" {
name = "example-template"
versions = [/* ... */]
acl = {
groups = [
{
id = data.coderd_group.employees.id
role = "use"
},
{
id = data.coderd_group.bosses.id
role = "admin"
}
]
users = []
}
}
19 changes: 19 additions & 0 deletions examples/data-sources/coderd_organization/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Get the default (first) organization for the coder deployment
data "coderd_organization" "default" {
is_default = true
}

// Get another organization by `id`
data "coderd_organization" "example" {
id = "abcd-efg-hijk"
}

data "coderd_organization" "example2" {
name = "example-organization-2"
}

// Create a group on a specific organization
resource "coderd_group" "example" {
name = "example-group"
organization_id = data.coderd_organization.default.id
}
9 changes: 9 additions & 0 deletions examples/data-sources/coderd_template/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Get a template on the provider's default organization by `id`
data "coderd_template" "example-template" {
id = "abcd-efg-hijk"
}

// Get a template on the provider's default organization by `name`
data "coderd_template" "example-template2" {
name = "example-template-2"
}
19 changes: 19 additions & 0 deletions examples/data-sources/coderd_user/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Get a user on the Coder deployment by `id`
data "coderd_user" "manager" {
id = "abcd-efg-hijk"
}

// Get a user on the Coder deployment by `username`
data "coderd_user" "admin" {
username = "admin"
}


// Use them to create a group
resource "coderd_group" "bosses" {
name = "group"
members = [
data.coderd_user.admin.id,
data.coderd_user.manager.id
]
}
Loading

0 comments on commit 43b6d91

Please sign in to comment.