You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coder templates are written in [Terraform](https://terraform.io). All Terraform modules, resources, and properties can be provisioned by Coder. The Coder server essentially runs a `terraform apply` every time a workspace is created/started/stopped.
4
4
5
5
Haven't written Terraform before? Check out Hashicorp's [Getting Started Guides](https://developer.hashicorp.com/terraform/tutorials).
6
6
7
-
## Key concepts in templates
7
+
## Architecture
8
8
9
-
There are some key concepts you should consider when writing templates.
9
+
This is a simplified diagram of our [Kubernetes example template](https://github.com/coder/coder/tree/main/examples/templates/kubernetes). Keep reading for a breakdown of each concept.
The [Coder Terraform provider](https://registry.terraform.io/providers/coder/coder/latest) makes it possible for standard Terraform resources (e.g. `docker_container`) to connect to Coder. Additionally, the provider lets you to customize the behavior of workspaces using your template.
13
+
## Coder Terraform Provider
14
+
15
+
The [Coder Terraform provider](https://registry.terraform.io/providers/coder/coder/latest) makes it possible for standard Terraform resources (e.g. `kubernetes_deployment`) to connect to Coder. Additionally, the provider lets you to customize the behavior of workspaces using your template.
14
16
15
17
```hcl
16
18
terraform {
@@ -22,54 +24,55 @@ terraform {
22
24
}
23
25
```
24
26
25
-
### coder_workspace
27
+
##coder_agent
26
28
27
-
This data source provides details about the state of a workspace, such as its name, owner, and whether the workspace is being started or stopped.
29
+
All templates need to create & run a Coder agent in order for developers to connect to their workspaces. The Coder agent is a service that runs inside the compute aspect of your workspace (typically a VM or container). You do not need to have any open ports, but the compute will need `curl` access to the Coder server.
28
30
29
-
The following snippet will create a container when the workspace is being started, and delete the container when it is stopped using Terraform's [count](https://developer.hashicorp.com/terraform/language/meta-arguments/count) meta-argument.
31
+
This snippet creates the agent, runs it inside the container via the `entrypoint`, and authenticates to Coder via the agent's token.
30
32
31
33
```hcl
32
-
data "coder_workspace" "me" {}
34
+
resource "coder_agent" "main" {
35
+
os = "linux"
36
+
arch = "amd64"
37
+
}
33
38
34
-
# Delete the container when workspace is stopped (count = 0)
Agents can also run startup scripts, set environment variables, and provide [metadata](../agent-metadata.md) about the workspace (e.g. CPU usage). Read the [coder_agent docs](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script) for more details.
45
47
46
-
All templates need to create & run a Coder agent in order for developers to connect to their workspaces. The Coder agent is a service that runs inside the compute aspect of your workspace (typically a VM or container).
48
+
## coder_workspace
47
49
48
-
This snippet creates the agent, runs it inside the container via the `entrypoint`, and authenticates to Coder via the agent's token.
50
+
This data source provides details about the state of a workspace, such as its name, owner, and whether the workspace is being started or stopped.
51
+
52
+
The following snippet will create a container when the workspace is being started, and delete the container when it is stopped using Terraform's [count](https://developer.hashicorp.com/terraform/language/meta-arguments/count) meta-argument.
Agents can also run startup scripts, set environment variables, and provide metadata about the workspace (e.g. CPU usage). Read the [coder_agent docs](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script) for more details.
63
+
# Persist the volume, even if stopped
64
+
resource "docker_volume" "projects" {}
65
+
```
64
66
65
-
###coder_app
67
+
## coder_app
66
68
67
-
Web apps that are running inside the workspace (e.g. `http://localhost:8080`) can be forwarded to the Coder dashboard with the `coder_app` resource. This is commonly used for [web IDEs](../ides/web-ides.md) such as code-server, RStudio, and JupyterLab. External apps, such as links to internal wikis or cloud consoles can also be embedded here.
69
+
Web apps that are running inside the workspace (e.g. `http://localhost:8080`) can be forwarded to the Coder dashboard with the `coder_app` resource. This is commonly used for [web IDEs](../../ides/web-ides.md) such as code-server, RStudio, and JupyterLab. External apps, such as links to internal wikis or cloud consoles can also be embedded here.
68
70
69
71
Apps are rendered on the workspace page:
70
72
71
-
![]()
73
+

72
74
75
+
The apps themselves have to be installed & running on the workspace. This can be done via the agent's startup script. See [web IDEs](../ides/web-ides.md) for some examples.
0 commit comments