Skip to content

Commit a8d92df

Browse files
authored
feat(vault-token): add optional vault enterprise namespace variable (#108)
Added an optional envvar to vault-token module to handle communicating with a non default vault namespace. in vault enterprise, you can run multiple secure isolated vault environments from the one vault server. each namespace has it's own authentication methods and secrets engines. vault uses the VAULT_NAMESPACE envvar to determine the namespace to use. no value, or either `root` or `/` will use the root (default) namespace, any other value will use a different namespace in vault community edition, the only supported namespace is "root", no other namespaces can be used. in HCP vault dedicated (the saas hosted version), you cant access vault without a namespace set this defaults to not setting the env var, so is backwards compatible, and works with vault CE --------- Co-authored-by: Birdie K <[email protected]>
1 parent 5a3ade7 commit a8d92df

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ variable "vault_token" {
2020
}
2121
2222
module "vault" {
23-
source = "registry.coder.com/coder/vault-token/coder"
24-
version = "1.1.0"
25-
agent_id = coder_agent.example.id
26-
vault_token = var.token # optional
27-
vault_addr = "https://vault.example.com"
23+
source = "registry.coder.com/coder/vault-token/coder"
24+
version = "1.2.0"
25+
agent_id = coder_agent.example.id
26+
vault_token = var.token # optional
27+
vault_addr = "https://vault.example.com"
28+
vault_namespace = "prod" # optional, vault enterprise only
2829
}
2930
```
3031

@@ -74,7 +75,7 @@ variable "vault_token" {
7475
7576
module "vault" {
7677
source = "registry.coder.com/coder/vault-token/coder"
77-
version = "1.1.0"
78+
version = "1.2.0"
7879
agent_id = coder_agent.example.id
7980
vault_addr = "https://vault.example.com"
8081
vault_token = var.token

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ variable "vault_token" {
2626
sensitive = true
2727
default = null
2828
}
29+
variable "vault_namespace" {
30+
type = string
31+
description = "The Vault namespace to use."
32+
default = null
33+
}
2934

3035
variable "vault_cli_version" {
3136
type = string
@@ -62,3 +67,10 @@ resource "coder_env" "vault_token" {
6267
name = "VAULT_TOKEN"
6368
value = var.vault_token
6469
}
70+
71+
resource "coder_env" "vault_namespace" {
72+
count = var.vault_namespace != null ? 1 : 0
73+
agent_id = var.agent_id
74+
name = "VAULT_NAMESPACE"
75+
value = var.vault_namespace
76+
}

0 commit comments

Comments
 (0)