Terraform
The Terraform Cloud secret backend for Vault generates Terraform Cloud API tokens dynamically for Organizations, Teams, and Users.
This page will show a quick start for this backend. For detailed documentation on every path, use vault path-help
after mounting the backend.
~> Terraform Enterprise Support: this secret engine supports both Terraform Cloud (app.terraform.io) as well as on-prem Terraform Enterprise. Any version requirements will be documented alongside the features that require them, if any.
Quick start
Most secrets engines must be configured in advance before they can perform their functions. These steps are usually completed by an operator or configuration management tool.
Enable the Terraform Cloud secrets engine:
By default, the secrets engine will mount at the name of the engine. To enable the secrets engine at a different path, use the
-path
argument.Configure Vault to connect and authenticate to Terraform Cloud:
See Terraform Cloud's documentation on API tokens to determine the appropriate API token for use with the secret engine. In order to perform all operations, a User API token is recommended.
Configure a role that maps a name in Vault to a Terraform Cloud User. At this time the Terraform Cloud API does not allow dynamic user generation. As a result this secret engine creates dynamic API tokens for an existing user, and manages the lifecycle of that API token. You will need to know the User ID in order to generate User API tokens for that user. You can use the Terraform Cloud Account API to find the desired User ID.
Usage
After the secrets engine is configured and a user/machine has a Vault token with the proper permission, it can generate credentials.
Generate a new credential by reading from the /creds
endpoint with the name of the role:
Organization, team, and user roles
Terraform Cloud supports three distinct types of API tokens; Organizations, Teams, and Users. Each token type has distinct access levels and generation workflows. A given Vault role can manage any one of the three types at a time, however there are important differences to be aware of.
Organization and team roles
The Terraform Cloud API limits both Organization and Team roles to one active token at any given time. Generating a new Organization or Team API token by reading the credentials in Vault or otherwise generating them on app.terraform.io will effectively revoke any existing API token for that Organization or Team.
Due to this behavior, Organization and Team API tokens created by Vault will be stored and returned on future requests, until the credentials get rotated. This is to prevent unintentional revocation of tokens that are currently in-use.
Below is an example of creating a Vault role to manage an Organization API token and rotating the token:
The API token is retrieved by reading the credentials for the role:
User roles
Traditionally, Vault secret engines create dynamic users and dynamic credentials along with them. At the time of writing, the Terraform Cloud API does not allow for creating dynamic users. Instead, the Terraform Cloud secret engine creates dynamic User API tokens by configuring a Vault role to manage an existing Terraform Cloud user. The lifecycle of these tokens is managed by Vault and will auto expire according to the configured TTL and max TTL of the Vault role.
Below is an example of creating a Vault role to manage manage User API tokens:
The API token is retrieved by reading the credentials for the role:
Please see the Terraform Cloud API Token documentation for more information.
Tutorial
Refer to Terraform Cloud Secrets Engine for a step-by-step tutorial.
API
The Terraform Cloud secrets engine has a full HTTP API. Please see the Terraform Cloud secrets engine API for more details.
Last updated