This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Add Hashicorp Vault Secrets Integration module #144
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,68 @@ | ||
--- | ||
display_name: "HCP Vault Secrets" | ||
description: "Fetch secrets from HCP Vault" | ||
icon: ../.icons/vault.svg | ||
maintainer_github: coder | ||
partner_github: hashicorp | ||
verified: true | ||
tags: [helper, integration, vault, hashicorp, hvs] | ||
--- | ||
|
||
# HCP Vault Secrets | ||
|
||
This module lets you fetch all or selective secrets from a [HCP Vault Secrets](https://developer.hashicorp.com/hcp/docs/vault-secrets) app into your [Coder](https://coder.com) workspaces. It makes use of the [`hcp_vault_secrets_app`](https://registry.terraform.io/providers/hashicorp/hcp/latest/docs/data-sources/vault_secrets_app) data source from the [HCP provider](https://registry.terraform.io/providers/hashicorp/hcp/latest). | ||
|
||
```tf | ||
module "vault" { | ||
source = "registry.coder.com/modules/hcp-vault-secrets/coder" | ||
version = "1.0.3" | ||
agent_id = coder_agent.example.id | ||
app_name = "demo-app" | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
To configure the HCP Vault Secrets module, you must create an HCP Service Principal from the HCP Vault Secrets app in the HCP console. This will give you the `HCP_CLIENT_ID` and `HCP_CLIENT_SECRET` that you need to authenticate with HCP Vault Secrets. See the [HCP Vault Secrets documentation](https://developer.hashicorp.com/hcp/docs/vault-secrets) for more information. | ||
|
||
## Fetch All Secrets | ||
|
||
To fetch all secrets from the HCP Vault Secrets app, skip the `secrets` input. | ||
|
||
```tf | ||
module "vault" { | ||
source = "registry.coder.com/modules/hcp-vault-secrets/coder" | ||
version = "1.0.3" | ||
agent_id = coder_agent.example.id | ||
app_name = "demo-app" | ||
} | ||
``` | ||
|
||
## Fetch Selective Secrets | ||
|
||
To fetch selective secrets from the HCP Vault Secrets app, set the `secrets` input. | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```tf | ||
module "vault" { | ||
source = "registry.coder.com/modules/hcp-vault-secrets/coder" | ||
version = "1.0.3" | ||
agent_id = coder_agent.example.id | ||
app_name = "demo-app" | ||
secrets = ["MY_SECRET_1", "MY_SECRET_2"] | ||
} | ||
``` | ||
|
||
## Set Client ID and Client Secret as Inputs | ||
|
||
Set `client_id` and `client_secret` as module inputs. | ||
|
||
```tf | ||
module "vault" { | ||
source = "registry.coder.com/modules/hcp-vault-secrets/coder" | ||
version = "1.0.3" | ||
agent_id = coder_agent.example.id | ||
app_name = "demo-app" | ||
client_id = "HCP_CLIENT_ID" | ||
client_secret = "HCP_CLIENT_SECRET" | ||
} | ||
``` |
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,67 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = ">= 0.12.4" | ||
} | ||
hcp = { | ||
source = "hashicorp/hcp" | ||
version = ">= 0.82.0" | ||
} | ||
} | ||
} | ||
|
||
provider "hcp" { | ||
client_id = var.client_id | ||
client_secret = var.client_secret | ||
} | ||
|
||
provider "coder" {} | ||
|
||
variable "agent_id" { | ||
type = string | ||
description = "The ID of a Coder agent." | ||
} | ||
|
||
variable "client_id" { | ||
type = string | ||
description = <<-EOF | ||
The client ID for the HCP Vault Secrets service principal. (Optional if HCP_CLIENT_ID is set as an environment variable.) | ||
EOF | ||
default = null | ||
sensitive = true | ||
} | ||
|
||
variable "client_secret" { | ||
type = string | ||
description = <<-EOF | ||
The client secret for the HCP Vault Secrets service principal. (Optional if HCP_CLIENT_SECRET is set as an environment variable.) | ||
EOF | ||
default = null | ||
sensitive = true | ||
} | ||
|
||
variable "app_name" { | ||
type = string | ||
description = "The name of the secrets app in HCP Vault Secrets" | ||
} | ||
|
||
variable "secrets" { | ||
type = list(string) | ||
description = "The names of the secrets to retrieve from HCP Vault Secrets" | ||
default = null | ||
} | ||
|
||
data "hcp_vault_secrets_app" "secrets" { | ||
app_name = var.app_name | ||
} | ||
|
||
resource "coder_env" "hvs_secrets" { | ||
# https://support.hashicorp.com/hc/en-us/articles/4538432032787-Variable-has-a-sensitive-value-and-cannot-be-used-as-for-each-arguments | ||
for_each = var.secrets != null ? toset(var.secrets) : nonsensitive(toset(keys(data.hcp_vault_secrets_app.secrets.secrets))) | ||
agent_id = var.agent_id | ||
name = each.key | ||
value = data.hcp_vault_secrets_app.secrets.secrets[each.key] | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.