Skip to content

Commit 5bc668a

Browse files
feat: add 1password module under bpmct namespace (#824)
Adds a 1Password module under the `bpmct` namespace. ## What it does Installs the [1Password CLI](https://developer.1password.com/docs/cli/) (`op`) into Coder workspaces at startup. Two auth paths: - **Service account token** — set `service_account_token` and `OP_SERVICE_ACCOUNT_TOKEN` is injected automatically. Fully headless. - **Personal account** — set `account_address`, `account_email`, `account_secret_key` to pre-register the account. User runs `op signin` in their terminal. Optionally installs the [1Password VS Code extension](https://marketplace.visualstudio.com/items?itemName=1Password.op-vscode) (`1Password.op-vscode`) for code-server and VS Code with `install_vscode_extension = true`. Supports `pre_install_script` and `post_install_script` for custom orchestration. ## What's included - `registry/bpmct/` — new namespace (Ben Potter, community) - `registry/bpmct/modules/1password/` — the module (`main.tf`, `run.sh`, `README.md`) - `.icons/1password.svg` — 1Password logo from Simple Icons ## Tested Spun up a dev Coder instance, pushed the template with a real 1Password service account token, created a workspace, and confirmed: - `op` CLI installs and authenticates - `op vault list` returns vaults - `1Password.op-vscode` extension installs in code-server --------- Co-authored-by: DevCats <christofer@coder.com>
1 parent caaff0c commit 5bc668a

6 files changed

Lines changed: 395 additions & 0 deletions

File tree

.icons/1password.svg

Lines changed: 1 addition & 0 deletions
Loading

registry/bpmct/.images/avatar.png

31.9 KB
Loading

registry/bpmct/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
display_name: Ben Potter
3+
bio: Tinkerer and Product Manager at Coder
4+
github: bpmct
5+
avatar: ./.images/avatar.png
6+
status: community
7+
---
8+
9+
# Ben Potter
10+
11+
Tinkerer and Product Manager at Coder. Building modules to make dev environments better.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
display_name: "1Password"
3+
description: "Install the 1Password CLI and VS Code extension in your Coder workspace"
4+
icon: ../../../../.icons/1password.svg
5+
verified: false
6+
tags: [integration, 1password, secrets]
7+
---
8+
9+
# 1Password
10+
11+
Install the [1Password CLI](https://developer.1password.com/docs/cli/)
12+
(`op`) in your Coder workspace and optionally authenticate with a service
13+
account token. Can also install the
14+
[1Password VS Code extension](https://marketplace.visualstudio.com/items?itemName=1Password.op-vscode)
15+
for code-server and VS Code.
16+
17+
```tf
18+
module "onepassword" {
19+
source = "registry.coder.com/bpmct/onepassword/coder"
20+
version = "1.0.0"
21+
agent_id = coder_agent.main.id
22+
service_account_token = var.op_service_account_token
23+
}
24+
```
25+
26+
## Authentication
27+
28+
### Service Account (recommended)
29+
30+
Create a [1Password service account](https://developer.1password.com/docs/service-accounts/get-started/)
31+
and pass the token as a Terraform variable. The module sets
32+
`OP_SERVICE_ACCOUNT_TOKEN` in the workspace so `op` commands work
33+
immediately.
34+
35+
```tf
36+
variable "op_service_account_token" {
37+
type = string
38+
sensitive = true
39+
}
40+
41+
module "onepassword" {
42+
source = "registry.coder.com/bpmct/onepassword/coder"
43+
version = "1.0.0"
44+
agent_id = coder_agent.main.id
45+
service_account_token = var.op_service_account_token
46+
}
47+
```
48+
49+
### Personal Account
50+
51+
Pass your account details and the module will pre-register the account.
52+
You'll be prompted for your password when you run `op signin` in the
53+
terminal.
54+
55+
```tf
56+
module "onepassword" {
57+
source = "registry.coder.com/bpmct/onepassword/coder"
58+
version = "1.0.0"
59+
agent_id = coder_agent.main.id
60+
account_address = "myteam.1password.com"
61+
account_email = "you@example.com"
62+
account_secret_key = var.op_secret_key
63+
}
64+
```
65+
66+
## VS Code Extension
67+
68+
Set `install_vscode_extension = true` to install the 1Password extension
69+
for code-server and VS Code.
70+
71+
```tf
72+
module "onepassword" {
73+
source = "registry.coder.com/bpmct/onepassword/coder"
74+
version = "1.0.0"
75+
agent_id = coder_agent.main.id
76+
service_account_token = var.op_service_account_token
77+
install_vscode_extension = true
78+
}
79+
```
80+
81+
## Custom Scripts
82+
83+
Run custom logic before or after the CLI is installed.
84+
85+
```tf
86+
module "onepassword" {
87+
source = "registry.coder.com/bpmct/onepassword/coder"
88+
version = "1.0.0"
89+
agent_id = coder_agent.main.id
90+
service_account_token = var.op_service_account_token
91+
post_install_script = <<-EOT
92+
op read "op://Vault/item/field" > ~/.secret
93+
EOT
94+
}
95+
```
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 0.17"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The ID of a Coder agent."
15+
}
16+
17+
variable "service_account_token" {
18+
type = string
19+
description = "A 1Password service account token. If set, account-based sign-in is skipped."
20+
default = ""
21+
sensitive = true
22+
}
23+
24+
variable "account_address" {
25+
type = string
26+
description = "The 1Password account sign-in address (e.g. myteam.1password.com)."
27+
default = ""
28+
}
29+
30+
variable "account_email" {
31+
type = string
32+
description = "The email address for the 1Password account."
33+
default = ""
34+
}
35+
36+
variable "account_secret_key" {
37+
type = string
38+
description = "The Secret Key for the 1Password account."
39+
default = ""
40+
sensitive = true
41+
}
42+
43+
variable "install_dir" {
44+
type = string
45+
description = "The directory to install the 1Password CLI to."
46+
default = "/usr/local/bin"
47+
}
48+
49+
variable "op_cli_version" {
50+
type = string
51+
description = "The version of the 1Password CLI to install."
52+
default = "latest"
53+
validation {
54+
condition = var.op_cli_version == "latest" || can(regex("^[0-9]+\\.[0-9]+\\.[0-9]+$", var.op_cli_version))
55+
error_message = "op_cli_version must be either 'latest' or a semantic version (e.g., '2.30.0')."
56+
}
57+
}
58+
59+
variable "install_vscode_extension" {
60+
type = bool
61+
description = "Install the 1Password VS Code extension for both VS Code and code-server."
62+
default = false
63+
}
64+
65+
variable "pre_install_script" {
66+
type = string
67+
description = "Custom script to run before installing the 1Password CLI."
68+
default = null
69+
}
70+
71+
variable "post_install_script" {
72+
type = string
73+
description = "Custom script to run after installing the 1Password CLI."
74+
default = null
75+
}
76+
77+
data "coder_parameter" "account_password" {
78+
count = var.account_address != "" && var.service_account_token == "" ? 1 : 0
79+
type = "string"
80+
name = "op_account_password"
81+
display_name = "1Password Account Password"
82+
description = "Your 1Password account password. Used to sign in to the CLI."
83+
mutable = true
84+
default = ""
85+
}
86+
87+
resource "coder_script" "1password" {
88+
agent_id = var.agent_id
89+
display_name = "1Password CLI"
90+
icon = "/icon/1password.svg"
91+
script = templatefile("${path.module}/run.sh", {
92+
SERVICE_ACCOUNT_TOKEN = var.service_account_token
93+
ACCOUNT_ADDRESS = var.account_address
94+
ACCOUNT_EMAIL = var.account_email
95+
ACCOUNT_SECRET_KEY = var.account_secret_key
96+
ACCOUNT_PASSWORD = var.account_address != "" && var.service_account_token == "" ? data.coder_parameter.account_password[0].value : ""
97+
INSTALL_DIR = var.install_dir
98+
OP_CLI_VERSION = var.op_cli_version
99+
INSTALL_VSCODE_EXTENSION = var.install_vscode_extension
100+
PRE_INSTALL_SCRIPT = var.pre_install_script != null ? base64encode(var.pre_install_script) : ""
101+
POST_INSTALL_SCRIPT = var.post_install_script != null ? base64encode(var.post_install_script) : ""
102+
})
103+
run_on_start = true
104+
start_blocks_login = true
105+
}
106+
107+
resource "coder_env" "op_service_account_token" {
108+
count = var.service_account_token != "" ? 1 : 0
109+
agent_id = var.agent_id
110+
name = "OP_SERVICE_ACCOUNT_TOKEN"
111+
value = var.service_account_token
112+
}

0 commit comments

Comments
 (0)