-
Notifications
You must be signed in to change notification settings - Fork 978
Pass git configuration variables via terraform #3034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
235ecc8
Pass workspace owner email address to provisioner
dwahler b7d919a
Remove owner_email and owner_username fields from agent metadata
dwahler 2e1415a
Add Git environment variables to example templates
dwahler 0910241
Remove "owner_name" field from provisioner metadata, use username ins…
dwahler 072ec6b
Remove Git configuration from most templates, add documentation
dwahler db9981d
Proofreading/typo fixes from @mafredri
dwahler c2b1c48
Update example templates to latest version of terraform-provider-coder
dwahler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,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 | ||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Creating & troubleshooting templates | ||||||
|
||||||
You can use any Terraform resources or modules with Coder! When working on | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,17 @@ 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! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}" | ||
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" | ||
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" | ||
} | ||
} | ||
|
||
resource "coder_app" "code-server" { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.