Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit cff60c4

Browse files
committed
add auth id var
1 parent 5a33af2 commit cff60c4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

github-upload-public-key/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ Templates that utilize Github External Auth can automatically ensure that the Co
1414
# Example
1515

1616
```tf
17+
data "coder_external_auth" "github" {
18+
id = "myauthid"
19+
}
20+
1721
module "github-upload-public-key" {
1822
source = "registry.coder.com/modules/github-upload-public-key/coder"
1923
version = "1.0.13"
2024
agent_id = coder_agent.example.id
25+
external_auth_id = data.coder_external_auth.github.id
2126
}
2227
```
2328

github-upload-public-key/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ variable "agent_id" {
1414
description = "The ID of a Coder agent."
1515
}
1616

17+
variable "external_auth_id" {
18+
type = string
19+
description = "The ID of the GitHub external auth."
20+
default = "github"
21+
}
22+
1723
resource "coder_script" "github_upload_public_key" {
1824
agent_id = var.agent_id
1925
script = templatefile("${path.module}/run.sh", {
2026
CODER_OWNER_SESSION_TOKEN : data.coder_workspace.me.owner_session_token,
2127
CODER_ACCESS_URL : data.coder_workspace.me.access_url,
28+
GITHUB_EXTERNAL_AUTH_ID : var.external_auth_id,
2229
})
2330
display_name = "Github Upload Public Key"
2431
icon = "/icon/github.svg"

github-upload-public-key/run.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44

55
CODER_ACCESS_URL="${CODER_ACCESS_URL}"
66
CODER_OWNER_SESSION_TOKEN="${CODER_OWNER_SESSION_TOKEN}"
7+
GITHUB_EXTERNAL_AUTH_ID="${GITHUB_EXTERNAL_AUTH_ID}"
78

89
if [ -z "$CODER_ACCESS_URL" ]; then
910
echo "No coder access url specified!"
@@ -15,8 +16,13 @@ if [ -z "$CODER_OWNER_SESSION_TOKEN" ]; then
1516
exit 1
1617
fi
1718

19+
if [ -z "$GITHUB_EXTERNAL_AUTH_ID" ]; then
20+
echo "No GitHub external auth id specified!"
21+
exit 1
22+
fi
23+
1824
echo "Fetching GitHub token..."
19-
GITHUB_TOKEN=$(coder external-auth access-token github)
25+
GITHUB_TOKEN=$(coder external-auth access-token $GITHUB_EXTERNAL_AUTH_ID)
2026
if [ $? -ne 0 ]; then
2127
echo "Failed to fetch GitHub token!"
2228
exit 1

0 commit comments

Comments
 (0)