Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7800a4

Browse files
docs: add coderd terraform provider (coder#14374)
1 parent 9f4f88f commit d7800a4

File tree

7 files changed

+137
-25
lines changed

7 files changed

+137
-25
lines changed

docs/admin/automation.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ All actions possible through the Coder dashboard can also be automated as it
44
utilizes the same public REST API. There are several ways to extend/automate
55
Coder:
66

7-
- [CLI](../reference/cli/README.md)
8-
- [REST API](../reference/api/README.md)
7+
- [coderd Terraform Provider](https://registry.terraform.io/providers/coder/coderd/latest)
8+
- [CLI](../reference/cli)
9+
- [REST API](../reference/api)
910
- [Coder SDK](https://pkg.go.dev/github.com/coder/coder/v2/codersdk)
1011

1112
## Quickstart
@@ -32,21 +33,25 @@ curl https://coder.example.com/api/v2/workspaces?q=owner:me \
3233

3334
## Documentation
3435

35-
We publish an [API reference](../reference/api/README.md) in our documentation.
36-
You can also enable a
37-
[Swagger endpoint](../reference/cli/server.md#--swagger-enable) on your Coder
38-
deployment.
36+
We publish an [API reference](../reference/api) in our documentation. You can
37+
also enable a [Swagger endpoint](../reference/cli/server.md#--swagger-enable) on
38+
your Coder deployment.
3939

4040
## Use cases
4141

4242
We strive to keep the following use cases up to date, but please note that
4343
changes to API queries and routes can occur. For the most recent queries and
44-
payloads, we recommend checking the CLI and API documentation.
44+
payloads, we recommend checking the relevant documentation.
45+
46+
### Users & Groups
47+
48+
- [Manage Users via Terraform](https://registry.terraform.io/providers/coder/coderd/latest/docs/resources/user)
49+
- [Manage Groups via Terraform](https://registry.terraform.io/providers/coder/coderd/latest/docs/resources/group)
4550

4651
### Templates
4752

48-
- [Update templates in CI](../templates/change-management.md): Store all
49-
templates and git and update templates in CI/CD pipelines.
53+
- [Manage templates via Terraform or CLI](../templates/change-management.md):
54+
Store all templates in git and update them in CI/CD pipelines.
5055

5156
### Workspace agents
5257

docs/admin/groups.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Groups
22

33
Groups can be used with [template RBAC](./rbac.md) to give groups of users
4-
access to specific templates. They can be defined in Coder or
5-
[synced from your identity provider](./auth.md#group-sync-enterprise).
4+
access to specific templates. They can be defined via the Coder web UI,
5+
[synced from your identity provider](./auth.md) or
6+
[managed via Terraform](https://registry.terraform.io/providers/coder/coderd/latest/docs/resources/template).
67

78
![Groups](../images/groups.png)
89

docs/admin/rbac.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Role Based Access Control (RBAC)
22

33
Use RBAC to define which users and [groups](./groups.md) can use specific
4-
templates in Coder. These can be defined in Coder or
5-
[synced from your identity provider](./auth.md)
4+
templates in Coder. These can be defined via the Coder web UI,
5+
[synced from your identity provider](./auth.md) or
6+
[managed via Terraform](https://registry.terraform.io/providers/coder/coderd/latest/docs/resources/template).
67

78
![rbac](../images/template-rbac.png)
89

docs/admin/workspace-proxies.md

+49-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ Workspace proxies can be used in the browser by navigating to the user
2626

2727
## Requirements
2828

29-
- The [Coder CLI](../reference/cli/README.md) must be installed and
30-
authenticated as a user with the Owner role.
29+
- The [Coder CLI](../reference/cli) must be installed and authenticated as a
30+
user with the Owner role.
31+
- Alternatively, the
32+
[coderd Terraform Provider](https://registry.terraform.io/providers/coder/coderd/latest)
33+
can be used to create and manage workspace proxies, if authenticated as a user
34+
with the Owner role.
3135

3236
## Step 1: Create the proxy
3337

@@ -198,6 +202,49 @@ FROM ghcr.io/coder/coder:latest
198202
ENTRYPOINT ["/opt/coder", "wsproxy", "server"]
199203
```
200204

205+
### Managing via Terraform
206+
207+
The
208+
[coderd Terraform Provider](https://registry.terraform.io/providers/coder/coderd/latest)
209+
can also be used to create and manage workspace proxies in the same Terraform
210+
configuration as your deployment.
211+
212+
```hcl
213+
214+
provider "coderd" {
215+
url = "https://coder.example.com"
216+
token = "****"
217+
}
218+
219+
resource "coderd_workspace_proxy" "sydney-wsp" {
220+
name = "sydney-wsp"
221+
display_name = "Australia (Sydney)"
222+
icon = "/emojis/1f1e6-1f1fa.png"
223+
}
224+
resource "kubernetes_deployment" "syd_wsproxy" {
225+
metadata { /* ... */ }
226+
spec {
227+
template {
228+
metadata { /* ... */ }
229+
spec {
230+
container {
231+
name = "syd-wsp"
232+
image = "ghcr.io/coder/coder:latest"
233+
args = ["wsproxy", "server"]
234+
env {
235+
name = "CODER_PROXY_SESSION_TOKEN"
236+
value = coderd_workspace_proxy.sydney-wsp.session_token
237+
}
238+
/* ... */
239+
}
240+
/* ... */
241+
}
242+
}
243+
/* ... */
244+
}
245+
}
246+
```
247+
201248
### Selecting a proxy
202249

203250
Users can select a workspace proxy at the top-right of the browser-based Coder

docs/architecture/validated-arch.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ could affect workspace users experience once the platform is live.
333333
1. Establish dedicated accounts for users with the _Template Administrator_
334334
role.
335335
1. Maintain Coder templates using
336-
[version control](../templates/change-management.md).
336+
[version control](../templates/change-management.md) and the
337+
[coderd Terraform Provider](https://registry.terraform.io/providers/coder/coderd/latest/docs).
337338
1. Consider implementing a GitOps workflow to automatically push new template
338339
versions into Coder from git. For example, on Github, you can use the
339340
[Update Coder Template](https://github.com/marketplace/actions/update-coder-template)

docs/templates/change-management.md

+64-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
11
# Template Change Management
22

3-
We recommend source-controlling your templates as you would other code. You can
4-
[install Coder](../install/) in CI/CD pipelines to push new template versions.
3+
We recommend source-controlling your templates as you would other any code, and
4+
automating the creation of new versions in CI/CD pipelines.
5+
6+
These pipelines will require tokens for your deployment. To cap token lifetime
7+
on creation,
8+
[configure Coder server to set a shorter max token lifetime](../reference/cli/server.md#--max-token-lifetime).
9+
10+
## coderd Terraform Provider
11+
12+
The
13+
[coderd Terraform provider](https://registry.terraform.io/providers/coder/coderd/latest)
14+
can be used to push new template versions, either manually, or in CI/CD
15+
pipelines. To run the provider in a CI/CD pipeline, and to prevent drift, you'll
16+
need to store the Terraform state
17+
[remotely](https://developer.hashicorp.com/terraform/language/settings/backends/configuration).
18+
19+
```hcl
20+
terraform {
21+
required_providers {
22+
coderd = {
23+
source = "coder/coderd"
24+
}
25+
}
26+
backend "gcs" {
27+
bucket = "example-bucket"
28+
prefix = "terraform/state"
29+
}
30+
}
31+
32+
provider "coderd" {
33+
// Can be populated from environment variables
34+
url = "https://coder.example.com"
35+
token = "****"
36+
}
37+
38+
// Get the commit SHA of the configuration's git repository
39+
variable "TFC_CONFIGURATION_VERSION_GIT_COMMIT_SHA" {
40+
type = string
41+
}
42+
43+
resource "coderd_template" "kubernetes" {
44+
name = "kubernetes"
45+
description = "Develop in Kubernetes!"
46+
versions = [{
47+
directory = ".coder/templates/kubernetes"
48+
active = true
49+
# Version name is optional
50+
name = var.TFC_CONFIGURATION_VERSION_GIT_COMMIT_SHA
51+
tf_vars = [{
52+
name = "namespace"
53+
value = "default4"
54+
}]
55+
}]
56+
/* ... Additional template configuration */
57+
}
58+
```
59+
60+
For an example, see how we push our development image and template
61+
[with GitHub actions](https://github.com/coder/coder/blob/main/.github/workflows/dogfood.yaml).
62+
63+
## Coder CLI
64+
65+
You can also [install Coder](../install/) to automate pushing new template
66+
versions in CI/CD pipelines.
567

668
```console
769
# Install the Coder CLI
@@ -25,8 +87,3 @@ coder templates push --yes $CODER_TEMPLATE_NAME \
2587
--directory $CODER_TEMPLATE_DIR \
2688
--name=$CODER_TEMPLATE_VERSION # Version name is optional
2789
```
28-
29-
To cap token lifetime on creation,
30-
[configure Coder server to set a shorter max token lifetime](../reference/cli/server.md#--max-token-lifetime).
31-
For an example, see how we push our development image and template
32-
[with GitHub actions](https://github.com/coder/coder/blob/main/.github/workflows/dogfood.yaml).

docs/templates/creating.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ here!
2525

2626
![Starter templates](../images/templates/starter-templates.png)
2727

28-
If you prefer to use Coder on the [command line](../reference/cli/README.md),
29-
use `coder templates init`.
28+
If you prefer to use Coder on the [command line](../reference/cli), use
29+
`coder templates init`.
3030

3131
> Coder starter templates are also available on our
3232
> [GitHub repo](https://github.com/coder/coder/tree/main/examples/templates).

0 commit comments

Comments
 (0)