Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion registry/coder/modules/coder-login/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Automatically logs the user into Coder when creating their workspace.
module "coder-login" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/coder-login/coder"
version = "1.0.31"
version = "1.1.0"
agent_id = coder_agent.example.id
}
```
Expand Down
17 changes: 8 additions & 9 deletions registry/coder/modules/coder-login/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ variable "agent_id" {
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

resource "coder_script" "coder-login" {
resource "coder_env" "coder_session_token" {
agent_id = var.agent_id
script = templatefile("${path.module}/run.sh", {
CODER_USER_TOKEN : data.coder_workspace_owner.me.session_token,
CODER_DEPLOYMENT_URL : data.coder_workspace.me.access_url
})
display_name = "Coder Login"
icon = "/icon/coder.svg"
run_on_start = true
start_blocks_login = true
name = "CODER_SESSION_TOKEN"
value = data.coder_workspace_owner.me.session_token
}

resource "coder_env" "coder_url" {
agent_id = var.agent_id
name = "CODER_URL"
value = data.coder_workspace.me.access_url
}
65 changes: 65 additions & 0 deletions registry/coder/modules/coder-login/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Test for coder-login module

run "test_coder_login_module" {
command = plan

variables {
agent_id = "test-agent-id"
}

# Test that the coder_env resources are created with correct configuration
assert {
condition = coder_env.coder_session_token.agent_id == "test-agent-id"
error_message = "CODER_SESSION_TOKEN agent ID should match the input variable"
}

assert {
condition = coder_env.coder_session_token.name == "CODER_SESSION_TOKEN"
error_message = "Environment variable name should be 'CODER_SESSION_TOKEN'"
}

assert {
condition = coder_env.coder_url.agent_id == "test-agent-id"
error_message = "CODER_URL agent ID should match the input variable"
}

assert {
condition = coder_env.coder_url.name == "CODER_URL"
error_message = "Environment variable name should be 'CODER_URL'"
}
}

# Test with mock data sources
run "test_with_mock_data" {
command = plan

variables {
agent_id = "mock-agent"
}

# Mock the data sources for testing
override_data {
target = data.coder_workspace.me
values = {
access_url = "https://coder.example.com"
}
}

override_data {
target = data.coder_workspace_owner.me
values = {
session_token = "mock-session-token"
}
}

# Verify environment variables get the mocked values
assert {
condition = coder_env.coder_url.value == "https://coder.example.com"
error_message = "CODER_URL should match workspace access_url"
}

assert {
condition = coder_env.coder_session_token.value == "mock-session-token"
error_message = "CODER_SESSION_TOKEN should match workspace owner session_token"
}
}
15 changes: 0 additions & 15 deletions registry/coder/modules/coder-login/run.sh

This file was deleted.