Pass git configuration variables via terraform (#3034)

* Pass workspace owner email address to provisioner

* Remove owner_email and owner_username fields from agent metadata

* Add Git environment variables to example templates

* Remove "owner_name" field from provisioner metadata, use username instead

* Remove Git configuration from most templates, add documentation

* Proofreading/typo fixes from @mafredri

* Update example templates to latest version of terraform-provider-coder
This commit is contained in:
David Wahler
2022-07-19 13:24:06 -05:00
committed by GitHub
parent b9847c18f4
commit f7ea016494
18 changed files with 144 additions and 120 deletions
+34 -4
View File
@@ -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.
@@ -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.
@@ -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" {
@@ -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
@@ -202,6 +207,31 @@ 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 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 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