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

Skip to content

Commit 072ec6b

Browse files
committed
Remove Git configuration from most templates, add documentation
1 parent 0910241 commit 072ec6b

File tree

11 files changed

+43
-64
lines changed

11 files changed

+43
-64
lines changed

docs/templates.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ code once you run `coder templates init` (new) or `coder templates pull`
4242
## Concepts in templates
4343

4444
While templates are written with standard Terraform, the
45-
[Coder Terraform Provider](https://registry.terraform.io/providers/coder/coder/latest/docs) is
45+
[Coder Terraform Provider](https://registry.terraform.io/providers/coder/coder/latest/docs) is
4646
used to define the workspace lifecycle and establish a connection from resources
4747
to Coder.
4848

@@ -51,7 +51,7 @@ template options, reference [Coder Terraform provider docs](https://registry.ter
5151

5252
### Resource
5353

54-
Resources in Coder are simply [Terraform resources](https://www.terraform.io/language/resources).
54+
Resources in Coder are simply [Terraform resources](https://www.terraform.io/language/resources).
5555
If a Coder agent is attached to a resource, users can connect directly to the resource over
5656
SSH or web apps.
5757

@@ -60,12 +60,12 @@ SSH or web apps.
6060
Once a Coder workspace is created, the Coder agent establishes a connection
6161
between a resource (docker_container) and Coder, so that a user can connect to
6262
their workspace from the web UI or CLI. A template can have multiple agents to
63-
allow users to connect to multiple resources in their workspace.
63+
allow users to connect to multiple resources in their workspace.
6464

6565
> Resources must download and start the Coder agent binary to connect to Coder.
6666
> This means the resource must be able to reach your Coder URL.
6767
68-
Use the Coder agent's init script to
68+
Use the Coder agent's init script to
6969

7070
```hcl
7171
data "coder_workspace" "me" {
@@ -90,6 +90,11 @@ resource "kubernetes_pod" "pod1" {
9090
}
9191
```
9292

93+
The `coder_agent` resource can be configured as described in the
94+
[documentation for the `coder` Terraform provider.](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent)
95+
For example, you can use the `env` property to set environment variables that will be
96+
inherited by all child processes of the agent, including SSH sessions.
97+
9398
### Parameters
9499

95100
Templates often contain _parameters_. These are defined by `variable` blocks in
@@ -202,6 +207,30 @@ By default, all templates allow developers to connect over SSH and a web
202207
terminal. See [Configuring Web IDEs](./ides/configuring-web-ides.md) to
203208
learn how to give users access to additional web applications.
204209

210+
### Data source
211+
212+
When a workspace is being started or stopped, the `coder_workspace` data source provides
213+
some useful parameters. See the [documentation for the `coder` Terraform provider](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace)
214+
for more information.
215+
216+
For example, the [Docker quick-start template](https://github.com/coder/coder/tree/main/examples/templates/docker)
217+
sets a few environment variables based on the username and email address of the user's owner, so
218+
that you can make Git commits immediately without any manual configuration:
219+
220+
```tf
221+
resource "coder_agent" "dev" {
222+
# ...
223+
env = {
224+
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
225+
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
226+
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
227+
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
228+
}
229+
}
230+
```
231+
232+
You can add these variable definitions to your own templates, or customize them however you like.
233+
205234
## Creating & troubleshooting templates
206235

207236
You can use any Terraform resources or modules with Coder! When working on

examples/templates/aws-linux/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ resource "coder_agent" "dev" {
7676
arch = "amd64"
7777
auth = "aws-instance-identity"
7878
os = "linux"
79-
env = {
80-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
81-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
82-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
83-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
84-
}
8579
}
8680

8781
locals {

examples/templates/aws-windows/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ resource "coder_agent" "dev" {
7373
arch = "amd64"
7474
auth = "aws-instance-identity"
7575
os = "windows"
76-
env = {
77-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
78-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
79-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
80-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
81-
}
8276
}
8377

8478
locals {

examples/templates/do-linux/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ data "coder_workspace" "me" {}
9696
resource "coder_agent" "dev" {
9797
os = "linux"
9898
arch = "amd64"
99-
env = {
100-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
101-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
102-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
103-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
104-
}
10599
}
106100

107101
resource "digitalocean_volume" "home_volume" {

examples/templates/docker-code-server/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ resource "coder_agent" "dev" {
3939
arch = var.docker_arch
4040
os = "linux"
4141
startup_script = "code-server --auth none"
42+
43+
# These environment variables allow you to make Git commits right away after creating a
44+
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
45+
# You can remove this block if you'd prefer to configure Git manually or using
46+
# dotfiles. (see docs/dotfiles.md)
4247
env = {
4348
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
4449
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"

examples/templates/docker-image-builds/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ data "coder_workspace" "me" {
6363
resource "coder_agent" "dev" {
6464
arch = var.step2_arch
6565
os = "linux"
66-
env = {
67-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
68-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
69-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
70-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
71-
}
7266
}
7367

7468
variable "docker_image" {

examples/templates/docker/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ resource "coder_agent" "dev" {
7474
curl -fsSL https://code-server.dev/install.sh | sh
7575
code-server --auth none --port 13337
7676
EOF
77+
78+
# These environment variables allow you to make Git commits right away after creating a
79+
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
80+
# You can remove this block if you'd prefer to configure Git manually or using
81+
# dotfiles. (see docs/dotfiles.md)
7782
env = {
7883
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
7984
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"

examples/templates/gcp-linux/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ resource "coder_agent" "dev" {
4949
auth = "google-instance-identity"
5050
arch = "amd64"
5151
os = "linux"
52-
env = {
53-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
54-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
55-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
56-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
57-
}
5852
}
5953

6054
resource "google_compute_instance" "dev" {

examples/templates/gcp-vm-container/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ resource "coder_agent" "dev" {
3939
auth = "google-instance-identity"
4040
arch = "amd64"
4141
os = "linux"
42-
env = {
43-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
44-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
45-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
46-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
47-
}
4842
}
4943

5044
module "gce-container" {

examples/templates/gcp-windows/main.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ resource "coder_agent" "dev" {
4949
auth = "google-instance-identity"
5050
arch = "amd64"
5151
os = "windows"
52-
env = {
53-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
54-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
55-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
56-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
57-
}
5852
}
5953

6054
resource "google_compute_instance" "dev" {

examples/templates/kubernetes-multi-service/main.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,16 @@ data "coder_workspace" "me" {}
4242
resource "coder_agent" "go" {
4343
os = "linux"
4444
arch = "amd64"
45-
env = {
46-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
47-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
48-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
49-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
50-
}
5145
}
5246

5347
resource "coder_agent" "java" {
5448
os = "linux"
5549
arch = "amd64"
56-
env = {
57-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
58-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
59-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
60-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
61-
}
6250
}
6351

6452
resource "coder_agent" "ubuntu" {
6553
os = "linux"
6654
arch = "amd64"
67-
env = {
68-
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
69-
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
70-
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
71-
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
72-
}
7355
}
7456

7557
resource "kubernetes_pod" "main" {

0 commit comments

Comments
 (0)