Skip to content

Conversation

@matifali
Copy link
Member

@matifali matifali commented Dec 2, 2025

Closes #50

This adds a new vault-cli module that:

  • Installs the Vault CLI
  • Optionally configures token authentication if provided
  • Optionally configures Vault Enterprise namespace if provided
  • Sets up VAULT_ADDR environment variable
  • Conditionally sets VAULT_TOKEN environment variable when token is provided
  • Conditionally sets VAULT_NAMESPACE environment variable when namespace is provided
  • Validates vault_cli_version must be latest or a semantic version (x.y.z)

The module can be used standalone for just CLI installation, or with a token and/or namespace for authentication scenarios.

Follow-up

As a follow-up, we will update the other vault modules (vault-github, vault-jwt, vault-token) to use this module for CLI installation, reducing code duplication.

@matifali matifali force-pushed the vault-optional-token-config branch 3 times, most recently from 2c450c7 to 060db3f Compare December 2, 2025 19:54
@matifali matifali requested a review from Copilot December 2, 2025 19:55
@matifali matifali force-pushed the vault-optional-token-config branch 2 times, most recently from d5811bc to c8a597c Compare December 2, 2025 20:02
@matifali matifali requested a review from rowansmithau December 2, 2025 20:03
Copilot finished reviewing on behalf of matifali December 2, 2025 20:04
@matifali matifali force-pushed the vault-optional-token-config branch from c8a597c to 3ae221e Compare December 2, 2025 20:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new vault-cli module that provides Vault CLI installation with optional token and namespace configuration. The module serves as a foundational component intended to reduce code duplication across existing vault modules (vault-github, vault-jwt, vault-token) in future updates.

Key Changes:

  • Adds Vault CLI installation with automatic version detection and multi-OS support
  • Implements optional token and namespace authentication via environment variables
  • Introduces semantic version validation for the Vault CLI version parameter

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
registry/coder/modules/vault-cli/run.sh Bash script implementing Vault CLI installation with OS detection, architecture mapping, and custom installation directory support
registry/coder/modules/vault-cli/main.tf Terraform module configuration with conditional environment variable resources for token and namespace
registry/coder/modules/vault-cli/main.tftest.hcl Comprehensive test suite covering various configuration scenarios including token, namespace, versioning, and validation cases
registry/coder/modules/vault-cli/README.md Module documentation with usage examples for different authentication scenarios and related module references

@matifali matifali force-pushed the vault-optional-token-config branch 2 times, most recently from 3a41d0d to dba2115 Compare December 2, 2025 20:22
@matifali matifali force-pushed the vault-optional-token-config branch 4 times, most recently from 0cd22f6 to fce6422 Compare December 2, 2025 20:40
…ation

Closes #50

This adds a new vault-cli module that:
- Installs the Vault CLI using the official HashiCorp releases API
- Uses jq to parse API response when available, falls back to sed
- Fetches download URL directly from API (with fallback to constructed URL)
- Optionally configures token authentication if provided
- Optionally configures Vault Enterprise namespace if provided
- Sets up VAULT_ADDR environment variable
- Conditionally sets VAULT_TOKEN environment variable when token is provided
- Conditionally sets VAULT_NAMESPACE environment variable when namespace is provided
- Validates vault_cli_version must be 'latest' or a semantic version without v prefix

The module can be used standalone for just CLI installation, or with
a token and/or namespace for authentication scenarios.
@matifali matifali force-pushed the vault-optional-token-config branch from fce6422 to e1f4a9a Compare December 2, 2025 20:41
@rowansmithau
Copy link
Contributor

given run.sh has reqs like jq, unzip, wget/curl etc, maybe this should be noted in README.md so consumers know what is needed to use this upfront?

Address review feedback:
- Combine fetch_stdout() and fetch() into single fetch() function
- fetch <url> outputs to stdout, fetch <url> <dest> writes to file
- HTTP client detection is cached and reused for both cases
- Fixes issue where curl was used explicitly for API calls but
  fetch() function supported wget/busybox
README validation requires Terraform code block in h1 section
…ments

The $${} syntax is Terraform template escaping which shellcheck
doesn't understand. Added disable directive for both case statements
in the fetch() function.
Copy link
Contributor

@rowansmithau rowansmithau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested myself locally with and without supplying a vault token, looks good to me

@matifali matifali merged commit 2cfbe5f into main Dec 4, 2025
4 checks passed
@matifali matifali deleted the vault-optional-token-config branch December 4, 2025 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vault-cli: create a new moudle that installs vault CLI in a workspace and puts it in the PATH

2 participants