Skip to content

Commit dd69d70

Browse files
committed
clear up config
1 parent d3ee450 commit dd69d70

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

registry/coder/modules/jupyterlab/README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
o---
22
display_name: JupyterLab
33
description: A module that adds JupyterLab in your Coder template.
44
icon: ../../../../.icons/jupyter.svg
@@ -23,15 +23,8 @@ module "jupyterlab" {
2323

2424
## Configuration
2525

26-
You can customize JupyterLab server settings by providing a JSON configuration:
27-
28-
The `config` parameter accepts a map of configuration settings that will be written to `~/.jupyter/jupyter_server_config.json` before JupyterLab starts. This allows you to configure any JupyterLab server settings according to the [JupyterLab configuration documentation](https://jupyter-server.readthedocs.io/en/latest/users/configuration.html).
29-
30-
### Frame Embedding Configuration
31-
32-
To allow JupyterLab to be embedded in Coder's iframe:
26+
JupyterLab is automatically configured to work with Coder's iframe embedding. For advanced configuration, you can use the `config` parameter to provide additional JupyterLab server settings according to the [JupyterLab configuration documentation](https://jupyter-server.readthedocs.io/en/latest/users/configuration.html).
3327

34-
**Set Content-Security-Policy for iframe embedding in Coder:**
3528
```tf
3629
module "jupyterlab" {
3730
count = data.coder_workspace.me.start_count
@@ -40,11 +33,14 @@ module "jupyterlab" {
4033
agent_id = coder_agent.example.id
4134
config = {
4235
ServerApp = {
36+
# Required for Coder Tasks iFrame embedding - do not remove
4337
tornado_settings = {
4438
headers = {
4539
"Content-Security-Policy" = "frame-ancestors 'self' ${data.coder_workspace.me.access_url}"
4640
}
4741
}
42+
# Your additional configuration here
43+
root_dir = "/workspace/notebooks"
4844
}
4945
}
5046
}

registry/coder/modules/jupyterlab/main.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ data "coder_workspace" "me" {}
1313
data "coder_workspace_owner" "me" {}
1414

1515
locals {
16-
config_json = jsonencode(var.config)
17-
config_b64 = length(var.config) > 0 ? base64encode(local.config_json) : ""
16+
# Fallback config with CSP for Coder iframe embedding when user config is empty
17+
csp_fallback_config = {
18+
ServerApp = {
19+
tornado_settings = {
20+
headers = {
21+
"Content-Security-Policy" = "frame-ancestors 'self' ${data.coder_workspace.me.access_url}"
22+
}
23+
}
24+
}
25+
}
26+
27+
# Use user config if provided, otherwise fallback to CSP config
28+
config_to_use = length(var.config) == 0 ? local.csp_fallback_config : var.config
29+
config_json = jsonencode(local.config_to_use)
30+
config_b64 = base64encode(local.config_json)
1831
}
1932

2033
# Add required variables for your modules and remove any unneeded variables
@@ -69,7 +82,6 @@ variable "config" {
6982
}
7083

7184
resource "coder_script" "jupyterlab_config" {
72-
count = length(var.config) > 0 ? 1 : 0
7385
agent_id = var.agent_id
7486
display_name = "JupyterLab Config"
7587
icon = "/icon/jupyter.svg"

0 commit comments

Comments
 (0)