Skip to content

Commit 3ae8c7d

Browse files
authored
feat: support optional installation of vault enterprise binary (#582)
## Description When using the SAML auth method with Vault and authenticating via CLI it is required to use the enterprise version of the binary, as SAML support is not built into the non enterprise version of the CLI. This PR adds an optional `enterprise` variable to support this. @matifali can you let me know the appropriate tag command to run to release this once approved, please? ## Type of Change - [ ] New module - [ ] New template - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information **Path:** `registry/coder/modules/vault-cli` **New version:** `v1.1.0` **Breaking change:** [ ] Yes [x] No ## Testing & Validation - [ ] Tests pass (`bun test`) - [ ] Code formatted (`bun fmt`) - [x] Changes tested locally ## Related Issues None
1 parent 2cfbe5f commit 3ae8c7d

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

registry/coder/modules/vault-cli/README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Installs the [Vault](https://www.vaultproject.io/) CLI and optionally configures
1313
```tf
1414
module "vault_cli" {
1515
source = "registry.coder.com/coder/vault-cli/coder"
16-
version = "1.0.0"
16+
version = "1.1.0"
1717
agent_id = coder_agent.example.id
1818
vault_addr = "https://vault.example.com"
1919
}
@@ -34,7 +34,7 @@ If you have a Vault token, you can provide it to automatically configure authent
3434
```tf
3535
module "vault_cli" {
3636
source = "registry.coder.com/coder/vault-cli/coder"
37-
version = "1.0.0"
37+
version = "1.1.0"
3838
agent_id = coder_agent.example.id
3939
vault_addr = "https://vault.example.com"
4040
vault_token = var.vault_token # Optional
@@ -50,7 +50,7 @@ Install the Vault CLI without any authentication:
5050
```tf
5151
module "vault_cli" {
5252
source = "registry.coder.com/coder/vault-cli/coder"
53-
version = "1.0.0"
53+
version = "1.1.0"
5454
agent_id = coder_agent.example.id
5555
vault_addr = "https://vault.example.com"
5656
}
@@ -61,7 +61,7 @@ module "vault_cli" {
6161
```tf
6262
module "vault_cli" {
6363
source = "registry.coder.com/coder/vault-cli/coder"
64-
version = "1.0.0"
64+
version = "1.1.0"
6565
agent_id = coder_agent.example.id
6666
vault_addr = "https://vault.example.com"
6767
vault_cli_version = "1.15.0"
@@ -73,7 +73,7 @@ module "vault_cli" {
7373
```tf
7474
module "vault_cli" {
7575
source = "registry.coder.com/coder/vault-cli/coder"
76-
version = "1.0.0"
76+
version = "1.1.0"
7777
agent_id = coder_agent.example.id
7878
vault_addr = "https://vault.example.com"
7979
install_dir = "/home/coder/bin"
@@ -87,14 +87,28 @@ For Vault Enterprise users who need to specify a namespace:
8787
```tf
8888
module "vault_cli" {
8989
source = "registry.coder.com/coder/vault-cli/coder"
90-
version = "1.0.0"
90+
version = "1.1.0"
9191
agent_id = coder_agent.example.id
9292
vault_addr = "https://vault.example.com"
9393
vault_token = var.vault_token
9494
vault_namespace = "admin/my-namespace"
9595
}
9696
```
9797

98+
### Vault Enterprise Binary
99+
100+
Install the Vault Enterprise binary. This is required if using SAML authentication to Vault:
101+
102+
```tf
103+
module "vault_cli" {
104+
source = "registry.coder.com/coder/vault-cli/coder"
105+
version = "1.1.0"
106+
agent_id = coder_agent.example.id
107+
vault_addr = "https://vault.example.com"
108+
enterprise = true
109+
}
110+
```
111+
98112
## Related Modules
99113

100114
For more advanced authentication methods, see:

registry/coder/modules/vault-cli/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ variable "vault_namespace" {
4848
default = null
4949
}
5050

51+
variable "enterprise" {
52+
type = bool
53+
description = "Whether to install the enterprise version of the Vault CLI. Required if using SAML authentication to Vault."
54+
default = false
55+
}
56+
5157
data "coder_workspace" "me" {}
5258

5359
resource "coder_script" "vault_cli" {
@@ -59,6 +65,7 @@ resource "coder_script" "vault_cli" {
5965
VAULT_TOKEN = var.vault_token
6066
INSTALL_DIR = var.install_dir
6167
VAULT_CLI_VERSION = var.vault_cli_version
68+
ENTERPRISE = var.enterprise
6269
})
6370
run_on_start = true
6471
start_blocks_login = true

registry/coder/modules/vault-cli/main.tftest.hcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,14 @@ run "test_vault_cli_with_token_and_namespace" {
163163
error_message = "VAULT_NAMESPACE should match the provided vault_namespace"
164164
}
165165
}
166+
167+
run "test_vault_cli_enterprise" {
168+
variables {
169+
enterprise = true
170+
}
171+
172+
assert {
173+
condition = resource.coder_script.vault_cli.display_name == "Vault CLI"
174+
error_message = "Display name should be 'Vault CLI'"
175+
}
176+
}

registry/coder/modules/vault-cli/run.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ VAULT_ADDR=${VAULT_ADDR}
55
VAULT_TOKEN=${VAULT_TOKEN}
66
INSTALL_DIR=${INSTALL_DIR}
77
VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
8+
ENTERPRISE=${ENTERPRISE}
89

910
# Fetch URL content. If dest is provided, write to file; otherwise output to stdout.
1011
# Usage: fetch <url> [dest]
@@ -75,9 +76,18 @@ install() {
7576

7677
# Fetch release information from HashiCorp API
7778
if [ "$${VAULT_CLI_VERSION}" = "latest" ]; then
78-
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/latest"
79+
if [ "$${ENTERPRISE}" = "true" ]; then
80+
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/latest?license_class=enterprise"
81+
else
82+
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/latest"
83+
fi
7984
else
80-
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/$${VAULT_CLI_VERSION}"
85+
# For specific version, append +ent suffix for enterprise
86+
if [ "$${ENTERPRISE}" = "true" ]; then
87+
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/$${VAULT_CLI_VERSION}+ent"
88+
else
89+
API_URL="https://api.releases.hashicorp.com/v1/releases/vault/$${VAULT_CLI_VERSION}"
90+
fi
8191
fi
8292

8393
API_RESPONSE=$(fetch "$${API_URL}")

0 commit comments

Comments
 (0)