HCP Terraform issues user tokens (Account settings → Tokens), team tokens, organization tokens and audit trail tokens, each shown only once and each with an expiration date. Terraform CLI picks a token up from terraform login or from a TF_TOKEN_<host> environment variable such as TF_TOKEN_app_terraform_io.
HCP Terraform (Terraform Cloud) key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| User token Removing someone from an SSO identity provider does not revoke their user token. Owners can disable user tokens for the organization. | — | Yes | Same permissions as the user account | Chosen at creation; organization owners can set a maximum time to live |
| Team token A team can hold several tokens with unique descriptions. Tokens without a description are legacy tokens, only one allowed. | — | Yes | Workspaces the team can access, not tied to a user | Has an expiration; cannot be changed after creation |
| Organization token One valid token per organization. | — | Yes | Create and configure workspaces and teams; cannot start runs or create configuration versions | Has an expiration; cannot be changed after creation |
| Audit trail token One valid token per organization. | — | Yes | Read audit trails | Has an expiration |
How to create a HCP Terraform (Terraform Cloud) key
- Click your user icon and choose Account settings, then Tokens.
- Click Create an API token and enter a description.
- Click Create API token and choose an expiration.
- Copy the token; HCP Terraform shows it only once.
Limiting what the key can do
User tokens carry all of the user's permissions, so prefer team tokens, which reach only the workspaces a team can access, for automation. Organization, audit trail and metrics service tokens have narrow, fixed purposes. Owners can set a maximum token lifetime in organization settings.
How to rotate a HCP Terraform (Terraform Cloud) key
- Create a new token with the same type and owner.
- Update
TF_TOKEN_app_terraform_io, CI secrets and credentials blocks. - Delete the old token.
The user token topic describes no rotate button; the approach is create a new token and revoke the old one. HCP Terraform emails 30 days and 7 days before expiration.
How to revoke a HCP Terraform (Terraform Cloud) key
- For a user token click the trash can icon next to it under Account settings → Tokens.
- For a team token delete it from the row's actions menu under Organization Settings → API Tokens → Team Tokens.
- Organization and audit trail tokens can be generated or revoked only by organization owners.
If your HCP Terraform (Terraform Cloud) key leaked
- Revoke the token immediately.
- Create a replacement with the shortest practical lifetime, preferring a team token over a user token.
- Review recent runs, workspace variables and state access for unexpected activity.
Environment variables and CLI
HCP Terraform (Terraform Cloud)'s SDKs and docs read the key from TF_TOKEN_app_terraform_io, TF_CLI_CONFIG_FILE or TFE_TOKEN.
Terraform CLI (terraform): terraform login fetches credentials in a browser and saves them to the CLI configuration file (.terraformrc, or terraform.rc on Windows); TF_TOKEN_ environment variables take priority over it
Things that catch people out
- The variable is
TF_TOKEN_plus the hostname with periods turned into underscores; hyphens are encoded as double underscores (Terraform v1.2.0 and later). - A
credentialsblock token must be a user or team token, not an organization token. - The Terraform MCP server reads
TFE_TOKENandTFE_ADDRESS, and keeps destructive operations off unlessENABLE_TF_OPERATIONSis enabled. - Agent API tokens are for agent pools only and are not valid for the HCP Terraform API.
Recent incidents that put HCP Terraform (Terraform Cloud) keys at risk
If you were affected by one of these, rotate your HCP Terraform (Terraform Cloud) keys using the rotation steps above.
- keyv, flat-cache and cache-manager npm releases carried a CI-secret stealer with a revocation trap 2026-08-04
Using your HCP Terraform (Terraform Cloud) key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a HCP Terraform (Terraform Cloud) key, these intents fit:
| Intent | What BotPassword does |
|---|---|
list_credentials | Lists the credentials this agent is granted and what it may do with each. Never values. |
request_access | Asks you for a grant, which you approve with your master password or decline in BotPassword on your desktop, never in the chat. The agent gets a receipt, never a value. Approval on your phone is planned. |
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
cli_login | Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned. |
rotate | Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet. |
capture_secret | Planned, not built yet: will read a newly created key straight from the page or command output into the vault. |
store_secret | Saves a value the agent already holds as a new vault item. |
HCP Terraform (Terraform Cloud) also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I create an HCP Terraform API token?
Click your user icon → Account settings → Tokens → Create an API token.
What is the environment variable for a Terraform Cloud token?
TF_TOKEN_app_terraform_io for the default host, following the TF_TOKEN_ plus host name pattern with periods as underscores.
Why does Terraform say the Terraform Cloud API token is not set?
Terraform has no credentials for the host; run terraform login or set the TF_TOKEN_ environment variable.
Do HCP Terraform tokens expire?
Yes. User, team and organization tokens all have an expiration, and expired tokens fail all API requests.
Can an AI agent use my HCP Terraform (Terraform Cloud) key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with list_credentials, run_with, http_request, so the agent gets the result and never the value.