Skip to content

docs: make template git auth example in sync with git auth setup example #7784

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 1 commit into from
Jun 1, 2023
Merged
Changes from all commits
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
126 changes: 64 additions & 62 deletions docs/templates/open-in-coder.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,70 @@ To support any infrastructure and software stack, Coder provides a generic appro

1. Modify your template to auto-clone repos:

- If you want the template to clone a specific git repo

```hcl
# Require git authentication to use this template
data "coder_git_auth" "github" {
id = "github"
}

resource "coder_agent" "dev" {
# ...
dir = "~/coder"
startup_script =<<EOF

# Clone repo from GitHub
if [ ! -d "coder" ]
then
git clone https://github.com/coder/coder
fi

EOF
}
```

> Note: The `dir` attribute can be set in multiple ways, for example:
>
> - `~/coder`
> - `/home/coder/coder`
> - `coder` (relative to the home directory)

- If you want the template to support any repository via [parameters](./parameters.md)

```hcl
# Require git authentication to use this template
data "coder_git_auth" "github" {
id = "github"
}

# Prompt the user for the git repo URL
data "coder_parameter" "git_repo" {
name = "git_repo"
display_name = "Git repository"
default = "https://github.com/coder/coder"
}

locals {
folder_name = try(element(split("/", data.coder_parameter.git_repo.value), length(split("/", data.coder_parameter.git_repo.value)) - 1), "")
}

resource "coder_agent" "dev" {
# ...
dir = "~/${local.folder_name}"
startup_script =<<EOF

# Clone repo from GitHub
if [ ! -d "${local.folder_name}" ]
then
git clone ${data.coder_parameter.git_repo.value}
fi

EOF
}
```
> The id in the template's `coder_git_auth` data source must match the `CODER_GITAUTH_0_ID` in the Coder deployment configuration.

- If you want the template to clone a specific git repo

```hcl
# Require git authentication to use this template
data "coder_git_auth" "github" {
id = "primary-github"
}

resource "coder_agent" "dev" {
# ...
dir = "~/coder"
startup_script =<<EOF

# Clone repo from GitHub
if [ ! -d "coder" ]
then
git clone https://github.com/coder/coder
fi

EOF
}
```

> Note: The `dir` attribute can be set in multiple ways, for example:
>
> - `~/coder`
> - `/home/coder/coder`
> - `coder` (relative to the home directory)

- If you want the template to support any repository via [parameters](./parameters.md)

```hcl
# Require git authentication to use this template
data "coder_git_auth" "github" {
id = "primary-github"
}

# Prompt the user for the git repo URL
data "coder_parameter" "git_repo" {
name = "git_repo"
display_name = "Git repository"
default = "https://github.com/coder/coder"
}

locals {
folder_name = try(element(split("/", data.coder_parameter.git_repo.value), length(split("/", data.coder_parameter.git_repo.value)) - 1), "")
}

resource "coder_agent" "dev" {
# ...
dir = "~/${local.folder_name}"
startup_script =<<EOF

# Clone repo from GitHub
if [ ! -d "${local.folder_name}" ]
then
git clone ${data.coder_parameter.git_repo.value}
fi

EOF
}
```

1. Embed the "Open in Coder" button with Markdown

Expand Down