Where values end up
| Technique | Hidden in CLI output? | Stored in state? | Stored in plan file? |
|---|---|---|---|
| Plain value | ✗ | ✓ | ✓ |
sensitive = true (variable, output, or provider schema) |
✓ | ✓ plaintext | ✓ |
Classic data source read (for example, a Vault secret) |
if the schema marks it sensitive | ✓ | ✓ |
Ephemeral variable (ephemeral = true, 1.10+) |
✓ | ✗ | ✗ |
Ephemeral resource (ephemeral block, 1.10+) |
✓ | ✗ | ✗ |
| Write-only argument (1.11+, provider-supported) | ✓ | ✗ (stored as null) | ✗ |
Ephemeral values (1.10+)
Ephemeral values exist only for the duration of one Terraform operation.
Ephemeral resources are opened each run, and they can renew and close leases. They're declared with an ephemeral block and referenced as ephemeral.<type>.<name>.
You can use ephemeral values only in contexts that don't persist:
- Other ephemeral variables and outputs
- Locals, which themselves become ephemeral
providerblocks- Provisioner and
connectionblocks - Write-only arguments
Putting an ephemeral value into a normal resource argument or a root module output is an error. Because ephemeral variables aren't stored in saved plans, they must be supplied again when you apply a saved plan.
Write-only arguments (1.11+)
Write-only arguments accept a value during apply, pass it to the provider, and are never persisted.
- By convention they end in
_wo, for examplepassword_wo. - They are usually paired with a
_wo_versionargument, because Terraform can't diff a value it never stored. Increment the version to push a new value. - They exist only where the provider implements them.
ephemeral "random_password" "app" { # random provider ≥ 3.7
length = 24
}
resource "vault_kv_secret_v2" "app" {
mount = "secret"
name = "app"
data_json_wo = jsonencode({ password = ephemeral.random_password.app.result })
data_json_wo_version = 1 # bump to rotate
}Secrets-management practices
- Never commit secrets in
.tfor.tfvarsfiles. Supply them throughTF_VAR_environment variables, a secrets manager, or HCP Terraform sensitive variables and variable sets. - Read secrets from Vault using ephemeral resources where the provider supports them. Classic Vault data sources write the secret into state.
- Eliminate static cloud credentials. Use HCP Terraform dynamic provider credentials (OIDC workload identity), or Vault-backed dynamic credentials, which issue short-lived credentials per run.
- Protect state anyway. Use a remote backend with encryption at rest, strict access control, and locking (Module 6), because many provider attributes are still stored.
- Treat saved plan files as sensitive.
nonsensitive()removes sensitivity marking. Use it only when the value is genuinely safe to display.