
- Purpose-built controls: rotation, access logging, and encryption at rest are provided by the secrets manager.
- Centralized rotation and access control: rotate a secret once and all consumers read the updated value; manage access with IAM/RBAC.
- Reduced exposure in code: secrets are not hard-coded in
.tfor.tfvarsfiles (note: secrets may still end up in state). - Single source of truth: Terraform, applications, and monitoring systems can all read the same centrally managed secret.

- The secret value is not present in your
.tfor.tfvarsfiles—only the reference to Secrets Manager is. - Terraform (or the CI runner executing Terraform) must have IAM permissions to read the secret.
- The secret value will typically be written to Terraform state after resource creation. Protect state using encrypted, access-controlled backends (for example, S3 + KMS with restricted IAM).
- The same concept applies to other platforms: use the Azure Key Vault, Google Secret Manager, or Vault data sources. Syntax differs, but the core idea—read at plan/apply and reference in resources—remains the same.
- HashiCorp Vault supports dynamic credentials, leasing, and short-lived secrets—features that increase security for production workloads. Consider Vault when you need dynamic secrets or granular programmatic control.
| Technique | Protects console logs/output | Protects Terraform state | Protects Git commits | Recommended use |
|---|---|---|---|---|
| Sensitive variables | Yes (hides output) | No (can still be in state) | Yes (reduces accidental exposure) | Use sensitive = true for variables/outputs to reduce accidental prints |
| Environment variables | Partially (depends on process logs) | No (values passed to Terraform can still be written to state) | Yes (keeps secrets out of files) | Use TF_VAR_* or AWS_* env vars for local dev and CI injection |
| External secret managers | Yes (prevents embedding in files) | No (state may still contain values) | Yes (secrets not in repo) | Use AWS Secrets Manager, Vault, Azure Key Vault, or Google Secret Manager for production |
- Store secrets in an external secrets manager for centralized lifecycle management and rotation.
- Inject secrets into the Terraform runtime via environment variables when appropriate (keeps secrets out of files).
- Mark variables and outputs as
sensitive = trueto avoid exposing values in logs and console output. - Protect Terraform state with a remote backend, encryption (for example, KMS), and least-privilege IAM roles; assume secrets may appear in state.
Even when you read secrets from an external manager, the secret values may end up in Terraform state. Make sure your state backend is encrypted and access is restricted (for example, use a remote backend with KMS encryption and least-privilege IAM).

- Protect inputs with
sensitivevariables. - Keep secrets out of version control by using environment variables for injection.
- Use an external secrets manager for production-grade security and centralized rotation.
- Secure your Terraform state—encrypt it, restrict access, and minimize sensitive data stored in it.