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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove Git configuration from most templates, add documentation
  • Loading branch information
dwahler committed Jul 18, 2022
commit 072ec6b468a00f5cec7506072fce60a5dd94116d
37 changes: 33 additions & 4 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ code once you run `coder templates init` (new) or `coder templates pull`
## Concepts in templates

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

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

### Resource

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

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

> Resources must download and start the Coder agent binary to connect to Coder.
> This means the resource must be able to reach your Coder URL.

Use the Coder agent's init script to
Use the Coder agent's init script to

```hcl
data "coder_workspace" "me" {
Expand All @@ -90,6 +90,11 @@ resource "kubernetes_pod" "pod1" {
}
```

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

### Parameters

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

### Data source

When a workspace is being started or stopped, the `coder_workspace` data source provides
some useful parameters. See the [documentation for the `coder` Terraform provider](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace)
for more information.

For example, the [Docker quick-start template](https://github.com/coder/coder/tree/main/examples/templates/docker)
sets a few environment variables based on the username and email address of the user's owner, so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sets a few environment variables based on the username and email address of the user's owner, so
sets a few environment variables based on the username and email address of the workspace's owner, so

that you can make Git commits immediately without any manual configuration:

```tf
resource "coder_agent" "dev" {
# ...
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}
```

You can add these variable definitions to your own templates, or customize them however you like.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can add these variable definitions to your own templates, or customize them however you like.
You can add these environment variable definitions to your own templates, or customize them however you like.


## Creating & troubleshooting templates

You can use any Terraform resources or modules with Coder! When working on
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/aws-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ resource "coder_agent" "dev" {
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

locals {
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/aws-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ resource "coder_agent" "dev" {
arch = "amd64"
auth = "aws-instance-identity"
os = "windows"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

locals {
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/do-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ data "coder_workspace" "me" {}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "digitalocean_volume" "home_volume" {
Expand Down
5 changes: 5 additions & 0 deletions examples/templates/docker-code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ resource "coder_agent" "dev" {
arch = var.docker_arch
os = "linux"
startup_script = "code-server --auth none"

# These environment variables allow you to make Git commits right away after creating a
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ For calling out this behavior!

# You can remove this block if you'd prefer to configure Git manually or using
# dotfiles. (see docs/dotfiles.md)
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/docker-image-builds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ data "coder_workspace" "me" {
resource "coder_agent" "dev" {
arch = var.step2_arch
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

variable "docker_image" {
Expand Down
5 changes: 5 additions & 0 deletions examples/templates/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ resource "coder_agent" "dev" {
curl -fsSL https://code-server.dev/install.sh | sh
code-server --auth none --port 13337
EOF

# These environment variables allow you to make Git commits right away after creating a
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
# You can remove this block if you'd prefer to configure Git manually or using
# dotfiles. (see docs/dotfiles.md)
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/gcp-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "google_compute_instance" "dev" {
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/gcp-vm-container/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

module "gce-container" {
Expand Down
6 changes: 0 additions & 6 deletions examples/templates/gcp-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "windows"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "google_compute_instance" "dev" {
Expand Down
18 changes: 0 additions & 18 deletions examples/templates/kubernetes-multi-service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,16 @@ data "coder_workspace" "me" {}
resource "coder_agent" "go" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_agent" "java" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_agent" "ubuntu" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "kubernetes_pod" "main" {
Expand Down