Repository navigation
feat: add 1password module under bpmct namespace #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
98a7ab1
feat: add 1password module under bpmct namespace
bpmct 3955e95
feat: add post_install_script support to 1password module
bpmct 4393712
fix: prettier formatting and shellcheck warning
bpmct f99adcb
refactor: address review feedback
bpmct 47f85c4
refactor: rename module directory from 1password to onepassword
bpmct 22becdb
chore: clean up run.sh comment artifacts
bpmct 72c50e1
Merge branch 'main' into bpmct/1password-module
DevelopmentCats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| display_name: Ben Potter | ||
| bio: Tinkerer and Product Manager at Coder | ||
| github: bpmct | ||
| avatar: ./.images/avatar.png | ||
| status: community | ||
| --- | ||
|
|
||
| # Ben Potter | ||
|
|
||
| Tinkerer and Product Manager at Coder. Building modules to make dev environments better. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| display_name: "1Password" | ||
| description: "Install the 1Password CLI and VS Code extension in your Coder workspace" | ||
| icon: ../../../../.icons/1password.svg | ||
| verified: false | ||
| tags: [integration, 1password, secrets] | ||
| --- | ||
|
|
||
| # 1Password | ||
|
|
||
| Install the [1Password CLI](https://developer.1password.com/docs/cli/) | ||
| (`op`) in your Coder workspace and optionally authenticate with a service | ||
| account token. Can also install the | ||
| [1Password VS Code extension](https://marketplace.visualstudio.com/items?itemName=1Password.op-vscode) | ||
| for code-server and VS Code. | ||
|
|
||
| ```tf | ||
| module "onepassword" { | ||
| source = "registry.coder.com/bpmct/onepassword/coder" | ||
| version = "1.0.0" | ||
| agent_id = coder_agent.main.id | ||
| service_account_token = var.op_service_account_token | ||
| } | ||
| ``` | ||
|
|
||
| ## Authentication | ||
|
|
||
| ### Service Account (recommended) | ||
|
|
||
| Create a [1Password service account](https://developer.1password.com/docs/service-accounts/get-started/) | ||
| and pass the token as a Terraform variable. The module sets | ||
| `OP_SERVICE_ACCOUNT_TOKEN` in the workspace so `op` commands work | ||
| immediately. | ||
|
|
||
| ```tf | ||
| variable "op_service_account_token" { | ||
| type = string | ||
| sensitive = true | ||
| } | ||
|
|
||
| module "onepassword" { | ||
| source = "registry.coder.com/bpmct/onepassword/coder" | ||
| version = "1.0.0" | ||
| agent_id = coder_agent.main.id | ||
| service_account_token = var.op_service_account_token | ||
| } | ||
| ``` | ||
|
|
||
| ### Personal Account | ||
|
|
||
| Pass your account details and the module will pre-register the account. | ||
| You'll be prompted for your password when you run `op signin` in the | ||
| terminal. | ||
|
|
||
| ```tf | ||
| module "onepassword" { | ||
| source = "registry.coder.com/bpmct/onepassword/coder" | ||
| version = "1.0.0" | ||
| agent_id = coder_agent.main.id | ||
| account_address = "myteam.1password.com" | ||
| account_email = "you@example.com" | ||
| account_secret_key = var.op_secret_key | ||
| } | ||
| ``` | ||
|
|
||
| ## VS Code Extension | ||
|
|
||
| Set `install_vscode_extension = true` to install the 1Password extension | ||
| for code-server and VS Code. | ||
|
|
||
| ```tf | ||
| module "onepassword" { | ||
| source = "registry.coder.com/bpmct/onepassword/coder" | ||
| version = "1.0.0" | ||
| agent_id = coder_agent.main.id | ||
| service_account_token = var.op_service_account_token | ||
| install_vscode_extension = true | ||
| } | ||
| ``` | ||
|
|
||
| ## Custom Scripts | ||
|
|
||
| Run custom logic before or after the CLI is installed. | ||
|
|
||
| ```tf | ||
| module "onepassword" { | ||
| source = "registry.coder.com/bpmct/onepassword/coder" | ||
| version = "1.0.0" | ||
| agent_id = coder_agent.main.id | ||
| service_account_token = var.op_service_account_token | ||
| post_install_script = <<-EOT | ||
| op read "op://Vault/item/field" > ~/.secret | ||
| EOT | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
|
|
||
| required_providers { | ||
| coder = { | ||
| source = "coder/coder" | ||
| version = ">= 0.17" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| variable "agent_id" { | ||
| type = string | ||
| description = "The ID of a Coder agent." | ||
| } | ||
|
|
||
| variable "service_account_token" { | ||
| type = string | ||
| description = "A 1Password service account token. If set, account-based sign-in is skipped." | ||
| default = "" | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "account_address" { | ||
| type = string | ||
| description = "The 1Password account sign-in address (e.g. myteam.1password.com)." | ||
| default = "" | ||
| } | ||
|
|
||
| variable "account_email" { | ||
| type = string | ||
| description = "The email address for the 1Password account." | ||
| default = "" | ||
| } | ||
|
|
||
| variable "account_secret_key" { | ||
| type = string | ||
| description = "The Secret Key for the 1Password account." | ||
| default = "" | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "install_dir" { | ||
| type = string | ||
| description = "The directory to install the 1Password CLI to." | ||
| default = "/usr/local/bin" | ||
| } | ||
|
|
||
| variable "op_cli_version" { | ||
| type = string | ||
| description = "The version of the 1Password CLI to install." | ||
| default = "latest" | ||
| validation { | ||
| condition = var.op_cli_version == "latest" || can(regex("^[0-9]+\\.[0-9]+\\.[0-9]+$", var.op_cli_version)) | ||
| error_message = "op_cli_version must be either 'latest' or a semantic version (e.g., '2.30.0')." | ||
| } | ||
| } | ||
|
|
||
| variable "install_vscode_extension" { | ||
| type = bool | ||
| description = "Install the 1Password VS Code extension for both VS Code and code-server." | ||
| default = false | ||
| } | ||
|
|
||
| variable "pre_install_script" { | ||
| type = string | ||
| description = "Custom script to run before installing the 1Password CLI." | ||
| default = null | ||
| } | ||
|
|
||
| variable "post_install_script" { | ||
| type = string | ||
| description = "Custom script to run after installing the 1Password CLI." | ||
| default = null | ||
| } | ||
|
|
||
| data "coder_parameter" "account_password" { | ||
| count = var.account_address != "" && var.service_account_token == "" ? 1 : 0 | ||
| type = "string" | ||
| name = "op_account_password" | ||
| display_name = "1Password Account Password" | ||
| description = "Your 1Password account password. Used to sign in to the CLI." | ||
| mutable = true | ||
| default = "" | ||
| } | ||
|
|
||
| resource "coder_script" "1password" { | ||
| agent_id = var.agent_id | ||
| display_name = "1Password CLI" | ||
| icon = "/icon/1password.svg" | ||
| script = templatefile("${path.module}/run.sh", { | ||
| SERVICE_ACCOUNT_TOKEN = var.service_account_token | ||
| ACCOUNT_ADDRESS = var.account_address | ||
| ACCOUNT_EMAIL = var.account_email | ||
| ACCOUNT_SECRET_KEY = var.account_secret_key | ||
| ACCOUNT_PASSWORD = var.account_address != "" && var.service_account_token == "" ? data.coder_parameter.account_password[0].value : "" | ||
| INSTALL_DIR = var.install_dir | ||
| OP_CLI_VERSION = var.op_cli_version | ||
| INSTALL_VSCODE_EXTENSION = var.install_vscode_extension | ||
| PRE_INSTALL_SCRIPT = var.pre_install_script != null ? base64encode(var.pre_install_script) : "" | ||
| POST_INSTALL_SCRIPT = var.post_install_script != null ? base64encode(var.post_install_script) : "" | ||
| }) | ||
| run_on_start = true | ||
| start_blocks_login = true | ||
| } | ||
|
|
||
| resource "coder_env" "op_service_account_token" { | ||
| count = var.service_account_token != "" ? 1 : 0 | ||
| agent_id = var.agent_id | ||
| name = "OP_SERVICE_ACCOUNT_TOKEN" | ||
| value = var.service_account_token | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.