Skip to content

Commit b108185

Browse files
feature (jetbrains-plugins): add module for installing jetbrains plugin (#772)
Co-authored-by: DevCats <christofer@coder.com> Co-authored-by: DevCats <chris@dualriver.com>
1 parent b725777 commit b108185

6 files changed

Lines changed: 417 additions & 0 deletions

File tree

18.9 KB
Loading

registry/harsh9485/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
display_name: Harsh Singh Panwar
3+
bio: Open source contributor
4+
github: Harsh9485
5+
avatar: ./.images/avatar.png
6+
status: community
7+
---
8+
9+
# Harsh Singh Panwar
10+
11+
Community modules for Coder workspaces.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
display_name: JetBrains Plugin Installer
3+
description: Companion module for coder/jetbrains that automatically installs JetBrains Marketplace plugins.
4+
icon: ../../../../.icons/jetbrains.svg
5+
tags: [ide, jetbrains, plugins]
6+
---
7+
8+
# JetBrains Plugin Installer
9+
10+
A companion module for
11+
[coder/jetbrains](https://registry.coder.com/modules/jetbrains) that
12+
automatically installs JetBrains Marketplace plugins into your workspace.
13+
14+
Use this alongside the core `coder/jetbrains` module — it handles plugin
15+
installation while `coder/jetbrains` handles IDE setup and Toolbox
16+
integration.
17+
18+
```tf
19+
module "jetbrains_plugins" {
20+
count = data.coder_workspace.me.start_count
21+
source = "registry.coder.com/harsh9485/jetbrains-plugins/coder"
22+
version = "0.1.0"
23+
agent_id = coder_agent.main.id
24+
25+
jetbrains_plugins = {
26+
"PY" = ["com.koxudaxi.pydantic", "com.intellij.kubernetes"]
27+
}
28+
}
29+
```
30+
31+
## Prerequisites
32+
33+
- The [coder/jetbrains](https://registry.coder.com/modules/jetbrains)
34+
module (or equivalent JetBrains Toolbox setup) must already be
35+
configured in your template.
36+
- `jq` must be available on `PATH`.
37+
- Linux environment only.
38+
39+
## Finding Plugin IDs
40+
41+
Open the plugin page on the
42+
[JetBrains Marketplace](https://plugins.jetbrains.com/). Scroll to
43+
**Additional Information** and copy the **Plugin ID**.
44+
45+
## Usage
46+
47+
```tf
48+
module "jetbrains" {
49+
count = data.coder_workspace.me.start_count
50+
source = "registry.coder.com/coder/jetbrains/coder"
51+
version = "1.4.0"
52+
agent_id = coder_agent.main.id
53+
folder = "/home/coder/project"
54+
default = ["PY", "GO"]
55+
}
56+
57+
module "jetbrains_plugins" {
58+
count = data.coder_workspace.me.start_count
59+
source = "registry.coder.com/harsh9485/jetbrains-plugins/coder"
60+
version = "0.1.0"
61+
agent_id = coder_agent.main.id
62+
63+
jetbrains_plugins = {
64+
"PY" = ["com.koxudaxi.pydantic", "com.intellij.kubernetes"]
65+
"GO" = ["org.jetbrains.plugins.go-template"]
66+
}
67+
}
68+
```
69+
70+
The keys in `jetbrains_plugins` are IDE product codes (`PY`, `GO`, `IU`,
71+
etc.) matching the codes used by the `coder/jetbrains` module. Each value
72+
is a list of Marketplace plugin IDs to install for that IDE.
73+
74+
> [!IMPORTANT]
75+
> After installing the IDE, restart the workspace. On the next start the
76+
> module detects installed IDEs and automatically installs the configured
77+
> plugins.
78+
79+
Some plugins may be disabled by default due to JetBrains security
80+
defaults — you might need to enable them manually in the IDE.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
run "no_script_when_plugins_empty" {
2+
command = plan
3+
4+
variables {
5+
agent_id = "foo"
6+
jetbrains_plugins = {}
7+
}
8+
9+
assert {
10+
condition = length(resource.coder_script.install_jetbrains_plugins) == 0
11+
error_message = "Expected no plugin install script when plugins map is empty"
12+
}
13+
}
14+
15+
run "script_created_when_plugins_provided" {
16+
command = plan
17+
18+
variables {
19+
agent_id = "foo"
20+
jetbrains_plugins = {
21+
"PY" = ["com.koxudaxi.pydantic", "com.intellij.kubernetes"]
22+
}
23+
}
24+
25+
assert {
26+
condition = length(resource.coder_script.install_jetbrains_plugins) == 1
27+
error_message = "Expected script to be created when plugins are provided"
28+
}
29+
}
30+
31+
run "rejects_invalid_product_code" {
32+
command = plan
33+
34+
variables {
35+
agent_id = "foo"
36+
jetbrains_plugins = {
37+
"INVALID" = ["com.example.plugin"]
38+
}
39+
}
40+
41+
expect_failures = [
42+
var.jetbrains_plugins,
43+
]
44+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
terraform {
2+
required_version = ">= 1.9"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 2.5"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The resource ID of a Coder agent."
15+
}
16+
17+
variable "jetbrains_plugins" {
18+
type = map(list(string))
19+
description = "Map of IDE product codes to plugin ID lists. Example: { IU = [\"com.foo\"], GO = [\"org.bar\"] }."
20+
default = {}
21+
22+
validation {
23+
condition = alltrue([
24+
for code in keys(var.jetbrains_plugins) : contains(
25+
["CL", "GO", "IU", "PS", "PY", "RD", "RM", "RR", "WS"], code
26+
)
27+
])
28+
error_message = "Keys must be valid JetBrains product codes: CL, GO, IU, PS, PY, RD, RM, RR, WS."
29+
}
30+
}
31+
32+
locals {
33+
plugin_map_b64 = base64encode(jsonencode(var.jetbrains_plugins))
34+
plugin_install_script = file("${path.module}/scripts/install_plugins.sh")
35+
}
36+
37+
resource "coder_script" "install_jetbrains_plugins" {
38+
count = length(var.jetbrains_plugins) > 0 ? 1 : 0
39+
agent_id = var.agent_id
40+
display_name = "Install JetBrains Plugins"
41+
run_on_start = true
42+
43+
script = <<-EOT
44+
#!/bin/bash
45+
set -o errexit
46+
set -o pipefail
47+
48+
CONFIG_DIR="$HOME/.config/JetBrains"
49+
50+
mkdir -p "$CONFIG_DIR"
51+
echo -n "${local.plugin_map_b64}" | base64 -d > "$CONFIG_DIR/plugins.json"
52+
chmod 600 "$CONFIG_DIR/plugins.json"
53+
54+
echo -n '${base64encode(local.plugin_install_script)}' | base64 -d > /tmp/install_plugins.sh
55+
chmod +x /tmp/install_plugins.sh
56+
57+
/tmp/install_plugins.sh
58+
EOT
59+
}

0 commit comments

Comments
 (0)