diff --git a/registry/coder/modules/filebrowser/README.md b/registry/coder/modules/filebrowser/README.md index 80ab3e853..ab668537a 100644 --- a/registry/coder/modules/filebrowser/README.md +++ b/registry/coder/modules/filebrowser/README.md @@ -14,7 +14,7 @@ A file browser for your workspace. module "filebrowser" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/filebrowser/coder" - version = "1.1.4" + version = "1.1.5" agent_id = coder_agent.main.id } ``` @@ -29,7 +29,7 @@ module "filebrowser" { module "filebrowser" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/filebrowser/coder" - version = "1.1.4" + version = "1.1.5" agent_id = coder_agent.main.id folder = "/home/coder/project" } @@ -41,7 +41,7 @@ module "filebrowser" { module "filebrowser" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/filebrowser/coder" - version = "1.1.4" + version = "1.1.5" agent_id = coder_agent.main.id database_path = ".config/filebrowser.db" } @@ -49,11 +49,13 @@ module "filebrowser" { ### Serve from the same domain (no subdomain) +When `subdomain = false`, you must also set `agent_name` to the name of your `coder_agent` resource. Coder serves path-based apps at `/@/./apps//`, so the agent name is required to build a base URL that matches the URL the user is actually browsing. If `agent_name` is omitted in this mode, `terraform apply` will fail with an explanatory error. + ```tf module "filebrowser" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/filebrowser/coder" - version = "1.1.4" + version = "1.1.5" agent_id = coder_agent.main.id agent_name = "main" subdomain = false diff --git a/registry/coder/modules/filebrowser/main.test.ts b/registry/coder/modules/filebrowser/main.test.ts index 1d925c35a..56beb998e 100644 --- a/registry/coder/modules/filebrowser/main.test.ts +++ b/registry/coder/modules/filebrowser/main.test.ts @@ -102,4 +102,19 @@ describe("filebrowser", async () => { testBaseLine(output); }, 15000); + + it("fails when subdomain=false and agent_name is not provided", async () => { + let caught: Error | undefined; + try { + await runTerraformApply(import.meta.dir, { + agent_id: "foo", + subdomain: false, + }); + } catch (e) { + caught = e as Error; + } + expect(caught).toBeDefined(); + expect(caught!.message).toContain("agent_name"); + expect(caught!.message).toContain("subdomain"); + }, 15000); }); diff --git a/registry/coder/modules/filebrowser/main.tf b/registry/coder/modules/filebrowser/main.tf index 498682dd8..e5285d0af 100644 --- a/registry/coder/modules/filebrowser/main.tf +++ b/registry/coder/modules/filebrowser/main.tf @@ -20,7 +20,7 @@ data "coder_workspace_owner" "me" {} variable "agent_name" { type = string - description = "The name of the coder_agent resource. (Only required if subdomain is false and the template uses multiple agents.)" + description = "The name of the coder_agent resource. Required when `subdomain` is `false` so the path-based base URL matches the URL Coder serves." default = null } @@ -102,6 +102,13 @@ resource "coder_script" "filebrowser" { SERVER_BASE_PATH : local.server_base_path }) run_on_start = true + + lifecycle { + precondition { + condition = var.subdomain || var.agent_name != null + error_message = "`agent_name` is required when `subdomain` is `false`. Coder always builds path-based app URLs as `/@/./apps//`, so the filebrowser base URL must include the agent name to match. Set `agent_name = \"\"` (e.g. `\"main\"`)." + } + } } resource "coder_app" "filebrowser" {