Skip to content

Commit 311327c

Browse files
authored
docs: git auth via template (#6850)
1 parent a8346bd commit 311327c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/admin/git-providers.md

+32
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,35 @@ To support regex matching for paths (e.g. github.com/orgname), you'll need to ad
9090
```console
9191
git config --global credential.useHttpPath true
9292
```
93+
94+
## Require git authentication in templates
95+
96+
If your template requires git authentication (e.g. running `git clone` in the [startup_script](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#startup_script)), you can require users authenticate via git prior to creating a workspace:
97+
98+
![Git authentication in template](../images/admin/git-auth-template.png)
99+
100+
The following example will require users authenticate via GitHub and auto-clone a repo
101+
into the `~/coder` directory.
102+
103+
```hcl
104+
data "coder_git_auth" "github" {
105+
# Matches the ID of the git auth provider in Coder.
106+
id = "github"
107+
}
108+
109+
resource "coder_agent" "dev" {
110+
os = "linux"
111+
arch = "amd64"
112+
dir = "~/coder"
113+
env = {
114+
GITHUB_TOKEN : data.coder_git_auth.github.access_token
115+
}
116+
startup_script = <<EOF
117+
if [ ! -d ~/coder ]; then
118+
git clone https://github.com/coder/coder
119+
fi
120+
EOF
121+
}
122+
```
123+
124+
See the [Terraform provider documentation](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/git_auth) for all available options.
279 KB
Loading

0 commit comments

Comments
 (0)