The problem with static credentials
When Terraform provisions infrastructure, it requires valid credentials for the target platform (AWS access keys, Azure service principals, GCP service account keys, Kubernetes tokens, etc.). A common approach issues long‑lived credentials to each Terraform user or CI runner. These credentials are often:- Stored locally on developers’ machines or in CI secrets stores.
- Difficult to rotate or revoke quickly.
- Hard to audit and manage when team members change or leave.
- Over‑privileged, increasing the attack surface.

Dynamic credential generation with Vault
Vault changes the model: instead of relying on durable static credentials, Vault vends short‑lived credentials on demand. A typical integration flow looks like this:- Terraform authenticates to Vault using an identity‑based authentication method (for example, AWS auth, Azure managed identity, Kubernetes service account, or AppRole), depending on where Terraform runs.
- Terraform requests credentials from Vault (often via the Vault provider or a data source).
- Vault’s secrets engine for the target platform (for example, the AWS secrets engine) generates credentials on demand and returns them to Terraform.
- Terraform uses those temporary credentials to provision or manage infrastructure.

Example Terraform integration
The following concise Terraform example demonstrates the pattern: configure the Vault provider, use a Vault data source to fetch temporary AWS credentials, and then pass those credentials to the AWS provider.Notes and best practices
- The
provider "vault"block tells Terraform how to reach Vault and how Terraform should authenticate to Vault. Choose the identity authentication method that matches where Terraform runs. - Use Vault provider data sources (or other provider constructs) to fetch temporary credentials. Names and attributes differ between Vault provider versions — check the provider docs for exact fields.
- Avoid persisting short‑lived secrets in Terraform state. Some provider/data-source combinations write credential material into state; prefer approaches that keep secrets transient (e.g., injected environment variables, external helpers, or providers that mark values as sensitive/ephemeral).
- In the example,
backendis the path to the Vault AWS secrets engine. Therolemaps to a Vault role that assembles the permission set for created credentials. - Depending on Terraform and provider behavior, you may need to supply credentials to the cloud provider via environment variables or runtime injection to prevent circular dependencies between providers and data sources.
- Not all cloud providers or Terraform providers expose data sources that generate ephemeral credentials. Confirm whether a provider supports short‑lived credentials and how credential material is handled.
Quick mapping: common Vault auth methods for Terraform runners
Static vs Dynamic credentials — a comparison
For the Terraform Associate exam, understand this pattern conceptually: Vault can generate short‑lived dynamic credentials; Terraform retrieves them (usually via the Vault provider/data sources); and using Vault reduces the need for long‑lived credentials and improves auditability and rotation.
Why adopt this pattern?
- Centralized secrets management: Vault is the single control plane for platform credentials.
- Reduced attack surface: short‑lived credentials expire quickly and can be revoked.
- No long‑lived local credentials: developers and CI systems do not need persistent platform keys.
- Easier permission changes: update Vault roles/policies instead of redistributing keys.
- Improved audit and compliance: Vault records issuance, revocation, and can enforce policies.
References and further reading
- HashiCorp Vault documentation: https://www.vaultproject.io/docs
- Vault AWS secrets engine: https://www.vaultproject.io/docs/secrets/aws
- Terraform provider for Vault: https://registry.terraform.io/providers/hashicorp/vault/latest
- Terraform documentation: https://www.terraform.io/docs