From aac27055e63db277f0a509b9cfccc00385e73508 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 29 Sep 2023 15:36:19 +0000 Subject: [PATCH] started coder-login --- coder-login/README.md | 18 ++++++++++++++++++ coder-login/main.tf | 39 +++++++++++++++++++++++++++++++++++++++ coder-login/run.sh | 13 +++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 coder-login/README.md create mode 100644 coder-login/main.tf create mode 100644 coder-login/run.sh diff --git a/coder-login/README.md b/coder-login/README.md new file mode 100644 index 0000000..ff79a47 --- /dev/null +++ b/coder-login/README.md @@ -0,0 +1,18 @@ +--- +display_name: Coder Login +description: Automatically logs the user into Coder on their workspace +icon: /emojis/1f511.png +maintainer_github: coder +verified: true +tags: [helper] +--- + +# Coder Login + +Automatically logs the user into Coder when creating their workspace. + +```hcl +module "coder-login" { + agent_id = coder_agent.example.id +} +``` \ No newline at end of file diff --git a/coder-login/main.tf b/coder-login/main.tf new file mode 100644 index 0000000..0bde3e3 --- /dev/null +++ b/coder-login/main.tf @@ -0,0 +1,39 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "coder_user_token" { + type = string + description = "Coder user token for authentication. Replace with second agent?" +} + +variable "coder_deployment_url" { + type = string + description = "Coder Deployment URL," +} + + +resource "coder_script" "personalize" { + agent_id = var.agent_id + script = templatefile("${path.module}/run.sh", { + CODER_USER_TOKEN : var.coder_user_token, + CODER_DEPLOYMENT_URL : var.coder_deployment_url + }) + display_name = "Personalize" + icon = "/icon/personalize.svg" + log_path = var.log_path + run_on_start = true + start_blocks_login = true +} diff --git a/coder-login/run.sh b/coder-login/run.sh new file mode 100644 index 0000000..12034cb --- /dev/null +++ b/coder-login/run.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# Logs the coder user in + +echo "Logging into Coder..." + +# Automatically authenticate the user if they are not +# logged in to another deployment +if ! coder list >/dev/null 2>&1; then + set +x; coder login --token=$CODER_USER_TOKEN --url=$CODER_DEPLOYMENT_URL +else + echo "You are already authenticated with coder" +fi