Skill 4.8.4

Secrets management with Vault

Key Concepts

Vault centralizes secrets with access policies, audit logs and leases. It can store static secrets in the key/value (KV) secrets engine and generate dynamic secrets, such as short-lived cloud credentials or database users, on request. Terraform reads them through the hashicorp/vault provider instead of storing secrets in variables or code.

Reading a secret with a Vault data source stores the secret in state. With Terraform 1.10 or later, use the provider's ephemeral resources, such as ephemeral "vault_kv_secret_v2", and pass the value to provider configurations or write-only arguments. Vault can also manage itself through Terraform, for example its policies and secrets engines, and HCP Terraform can obtain Vault tokens through dynamic provider credentials.