Terraform & OpenTofu Credentials Helper
Use dotsecenv as a credentials helper for Terraform and OpenTofu. Registry and backend tokens (e.g., Terraform Cloud) are encrypted at rest in your vault — no plaintext credentials blocks in your CLI config.
How It Works
Section titled “How It Works”Terraform and OpenTofu call the credentials helper with three verbs:
| Verb | Action | dotsecenv behavior |
|---|---|---|
get <host> | Retrieve credentials for a registry | Returns stored JSON from vault, or {} if none |
store <host> | Save credentials (JSON on stdin) | Validates and stores the full JSON object in vault |
forget <host> | Remove credentials for a registry | Marks the secret as deleted in vault |
Terraform passes the registry hostname (e.g., app.terraform.io) as the key. The helper stores it as a dotsecenv secret under that hostname. The full JSON credentials object is stored as-is, preserving all properties.
Prerequisites
Section titled “Prerequisites”- dotsecenv installed and configured with at least one vault (see Getting Started)
- Terraform >= 0.13 or OpenTofu >= 1.6
Installation
Section titled “Installation”Credentials helpers must be placed in one of Terraform’s default plugin search locations. The most portable location across all platforms is ~/.terraform.d/plugins/.
The terraform-credentials-dotsecenv helper is included in the deb, rpm, and Arch packages and installed to /usr/share/terraform/plugins/.
Verify it’s available:
ls /usr/share/terraform/plugins/terraform-credentials-dotsecenvAfter installing dotsecenv via Homebrew, the helper is included in the release archive. Symlink it into a plugin directory:
mkdir -p ~/.terraform.d/pluginsln -s "$(brew --prefix dotsecenv)/contrib/terraform-credentials-dotsecenv" \ ~/.terraform.d/plugins/terraform-credentials-dotsecenvDownload the helper script from the release archive or copy it from contrib/terraform-credentials-dotsecenv:
# Linux / XDG Base Directory fallbackPLUGIN_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/terraform/plugins"mkdir -p "$PLUGIN_DIR"curl -fsSL https://raw.githubusercontent.com/dotsecenv/dotsecenv/main/contrib/terraform-credentials-dotsecenv \ -o "$PLUGIN_DIR/terraform-credentials-dotsecenv"chmod +x "$PLUGIN_DIR/terraform-credentials-dotsecenv"Configuration
Section titled “Configuration”-
Verify the helper is installed
Check that the binary exists in a plugin directory and is executable:
Terminal window ls -l ~/.terraform.d/plugins/terraform-credentials-dotsecenvQuick smoke test:
Terminal window ~/.terraform.d/plugins/terraform-credentials-dotsecenv get app.terraform.io# Should print: {} -
Add to CLI config
Add to
~/.terraformrc:credentials_helper "dotsecenv" {args = []}Add to
~/.tofurc:credentials_helper "dotsecenv" {args = []}
terraform login
Section titled “terraform login”Log in to a registry (e.g., Terraform Cloud):
terraform loginTerraform generates an API token and calls store to save it through dotsecenv. The token is encrypted and stored in your vault under the registry hostname (e.g., app.terraform.io).
terraform logout
Section titled “terraform logout”terraform logoutTerraform calls forget to mark the credentials as deleted in your vault.
Manual operations
Section titled “Manual operations”You can also call the helper directly. Terraform normally does this automatically, but manual calls are useful for debugging or scripting:
# Storeecho '{"token":"my-api-token"}' | terraform-credentials-dotsecenv store app.terraform.io
# Retrieveterraform-credentials-dotsecenv get app.terraform.io
# Removeterraform-credentials-dotsecenv forget app.terraform.ioVerifying the setup
Section titled “Verifying the setup”After terraform login, confirm the token is stored in your vault:
dotsecenv secret get app.terraform.io --json{ "added_at": "2026-01-15T10:30:00Z", "value": { "token": "my-api-token" }, "vault": "~/.secenv.vault"}Troubleshooting
Section titled “Troubleshooting”| Problem | Cause | Solution |
|---|---|---|
terraform login fails with “credentials helper not found” | Helper not in a plugin directory | Check it exists in ~/.terraform.d/plugins/ and is executable |
store fails with “not valid JSON” | Malformed input | Check the JSON is well-formed with echo '...' | python3 -m json.tool |
store fails with “must contain a ‘token’ property” | Missing token key | Terraform always sends a token property — check for manual input errors |
get returns {} for a stored secret | Secret key case mismatch | dotsecenv normalizes keys to UPPERCASE; check with dotsecenv secret get |
GPG passphrase prompt during terraform init | GPG agent not caching | Configure gpg-agent with a longer cache TTL in ~/.gnupg/gpg-agent.conf |
Next Steps
Section titled “Next Steps”- Getting Started — Set up dotsecenv and your first vault
- CLI Reference — Full command documentation
- Security Model — How encryption and access control work