From cff60c4a7ed1c9b8d1504923c1deac9ce5160cd0 Mon Sep 17 00:00:00 2001 From: Garrett Delfosse Date: Tue, 30 Apr 2024 16:53:47 +0000 Subject: [PATCH] add auth id var --- github-upload-public-key/README.md | 5 +++++ github-upload-public-key/main.tf | 7 +++++++ github-upload-public-key/run.sh | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/github-upload-public-key/README.md b/github-upload-public-key/README.md index 98c27c1..21d0287 100644 --- a/github-upload-public-key/README.md +++ b/github-upload-public-key/README.md @@ -14,10 +14,15 @@ Templates that utilize Github External Auth can automatically ensure that the Co # Example ```tf +data "coder_external_auth" "github" { + id = "myauthid" +} + module "github-upload-public-key" { source = "registry.coder.com/modules/github-upload-public-key/coder" version = "1.0.13" agent_id = coder_agent.example.id + external_auth_id = data.coder_external_auth.github.id } ``` diff --git a/github-upload-public-key/main.tf b/github-upload-public-key/main.tf index 313d716..e370357 100644 --- a/github-upload-public-key/main.tf +++ b/github-upload-public-key/main.tf @@ -14,11 +14,18 @@ variable "agent_id" { description = "The ID of a Coder agent." } +variable "external_auth_id" { + type = string + description = "The ID of the GitHub external auth." + default = "github" +} + resource "coder_script" "github_upload_public_key" { agent_id = var.agent_id script = templatefile("${path.module}/run.sh", { CODER_OWNER_SESSION_TOKEN : data.coder_workspace.me.owner_session_token, CODER_ACCESS_URL : data.coder_workspace.me.access_url, + GITHUB_EXTERNAL_AUTH_ID : var.external_auth_id, }) display_name = "Github Upload Public Key" icon = "/icon/github.svg" diff --git a/github-upload-public-key/run.sh b/github-upload-public-key/run.sh index fa8e115..b31a9d3 100755 --- a/github-upload-public-key/run.sh +++ b/github-upload-public-key/run.sh @@ -4,6 +4,7 @@ set -e CODER_ACCESS_URL="${CODER_ACCESS_URL}" CODER_OWNER_SESSION_TOKEN="${CODER_OWNER_SESSION_TOKEN}" +GITHUB_EXTERNAL_AUTH_ID="${GITHUB_EXTERNAL_AUTH_ID}" if [ -z "$CODER_ACCESS_URL" ]; then echo "No coder access url specified!" @@ -15,8 +16,13 @@ if [ -z "$CODER_OWNER_SESSION_TOKEN" ]; then exit 1 fi +if [ -z "$GITHUB_EXTERNAL_AUTH_ID" ]; then + echo "No GitHub external auth id specified!" + exit 1 +fi + echo "Fetching GitHub token..." -GITHUB_TOKEN=$(coder external-auth access-token github) +GITHUB_TOKEN=$(coder external-auth access-token $GITHUB_EXTERNAL_AUTH_ID) if [ $? -ne 0 ]; then echo "Failed to fetch GitHub token!" exit 1