- Highly privileged
- Stored locally on developer machines or CI runners
- Hard to rotate or revoke
- Difficult to audit

- Terraform authenticates to Vault via an identity-based auth method (AWS Auth, Azure roles, Kubernetes service account token, etc.), chosen based on where Terraform runs.
- Vault uses the appropriate secrets engine (AWS, Azure, GCP, Kubernetes, etc.) to generate credentials on demand.
- Vault returns temporary credentials to Terraform.
- Terraform uses these temporary credentials to authenticate to the cloud provider for the current run.
- Vault provider configuration (how Terraform connects to Vault and authenticates).
- An ephemeral construct that fetches dynamic credentials from Vault (conceptual in this example).
- A cloud provider block that consumes the temporary credentials returned by that ephemeral construct.
- A normal resource that is provisioned with those credentials.
data "vault_aws_access_credentials") or provider-specific constructs to obtain temporary credentials without persisting them to state. Check the provider docs for exact syntax.
- On
terraform planorterraform apply, Terraform authenticates to Vault using the configured auth method. - Terraform requests dynamic credentials from the relevant Vault secrets engine (e.g., AWS secrets engine).
- Vault vends temporary credentials and returns them to Terraform; Terraform uses them for provider authentication during the run.
- Credentials have a short TTL (minutes or tens of minutes). When the TTL expires Vault revokes the backend credential (in AWS, Azure, GCP, etc.), preventing later misuse even if the credentials were exposed.
- Credentials are generated on demand and are short-lived (TTL-based).
- Roles in Vault can scope credentials to least privilege.
- Long-lived cloud credentials remain inside Vault; users do not hold platform secrets.
- When using ephemeral resources or provider mechanisms that avoid persisting secrets, credentials can be kept out of Terraform state — they exist only in memory for the run.
- Reduces credential sprawl, simplifies rotation/revocation, and reduces the attack surface.
Not all Terraform providers expose ephemeral resource types. Check the provider documentation to confirm whether ephemeral resources or equivalent data sources are available and how to reference them.
Avoid persisting dynamic credentials to state files or logs. If a provider does not support ephemeral constructs, carefully review how credentials are surfaced and ensure they are not saved to persistent state or exposed in CI logs.
| Component | Responsibility | Example or note |
|---|---|---|
| Vault | Centralized secrets management, dynamic credential generation, policy enforcement | See Vault docs: https://www.vaultproject.io/docs |
| Vault secrets engine | Generates backend credentials (AWS, Azure, GCP, etc.) | Configure the appropriate secrets engine for your cloud |
| Vault auth method | Authenticates Terraform to Vault (Kubernetes, AWS, Azure, etc.) | Choose based on where Terraform runs |
| Terraform Vault provider | Retrieves credentials from Vault | provider "vault" { ... } |
| Ephemeral/data construct | Returns temporary credentials to Terraform without persisting to state | data "vault_aws_access_credentials" ... or provider-specific ephemeral block |
| Cloud provider | Uses temporary credentials for API calls | provider "aws" { access_key = ... secret_key = ... } |
- Centralized secrets management and policy control via Vault.
- Reduced attack surface because credentials are short-lived and revocable.
- No local long-lived credential storage for developers or CI runners.
- Easier to change access controls by updating Vault roles/policies without redistributing credentials.
- Vault can generate dynamic, short-lived credentials for cloud platforms.
- Terraform uses the Vault provider to retrieve those credentials.
- Combining Vault with ephemeral resources or provider-specific mechanisms avoids writing credentials to state.
- You do not need to be an expert in Vault; understand the integration and security benefits.
- HashiCorp Vault documentation: https://www.vaultproject.io/docs
- Terraform Registry (providers): https://registry.terraform.io/browse/providers
- Provider-specific Vault integrations (search the registry for
vault_*data sources/providers) - Terraform Associate exam course (reference)