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

Commit 1ed25f4

Browse files
authored
Merge pull request #68 from coder/coder-login
add coder-login
2 parents b1be451 + 23ca3bd commit 1ed25f4

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

.icons/coder-white.svg

Lines changed: 8 additions & 0 deletions
Loading

.images/coder-login.png

99.6 KB
Loading

coder-login/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
display_name: Coder Login
3+
description: Automatically logs the user into Coder on their workspace
4+
icon: ../.icons/coder-white.svg
5+
maintainer_github: coder
6+
verified: true
7+
tags: [helper]
8+
---
9+
10+
# Coder Login
11+
12+
Automatically logs the user into Coder when creating their workspace.
13+
14+
```hcl
15+
module "coder-login" {
16+
agent_id = coder_agent.example.id
17+
}
18+
```
19+
20+
![Coder Login Logs](../.images/coder-login.png)

coder-login/main.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
executeScriptInContainer,
4+
runTerraformApply,
5+
runTerraformInit,
6+
testRequiredVariables,
7+
} from "../test";
8+
9+
describe("coder-login", async () => {
10+
await runTerraformInit(import.meta.dir);
11+
12+
testRequiredVariables(import.meta.dir, {
13+
agent_id: "foo",
14+
});
15+
});

coder-login/main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 0.12"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The ID of a Coder agent."
15+
}
16+
17+
data "coder_workspace" "me" {}
18+
19+
resource "coder_script" "coder-login" {
20+
agent_id = var.agent_id
21+
script = templatefile("${path.module}/run.sh", {
22+
CODER_USER_TOKEN : data.coder_workspace.me.owner_session_token,
23+
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
24+
})
25+
display_name = "Coder Login"
26+
icon = "http://svgur.com/i/y5G.svg"
27+
run_on_start = true
28+
start_blocks_login = true
29+
}
30+

coder-login/run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env sh
2+
3+
# Automatically authenticate the user if they are not
4+
# logged in to another deployment
5+
6+
BOLD='\033[0;1m'
7+
8+
printf "$${BOLD}Logging into Coder...\n\n$${RESET}"
9+
10+
if ! coder list >/dev/null 2>&1; then
11+
set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
12+
else
13+
echo "You are already authenticated with coder."
14+
fi

0 commit comments

Comments
 (0)