Redaction, Temporary Values and Write-Only Inputs Solve Different Problems
A hotel front desk handles keys three ways. A guest's key sits in an opaque sleeve, so the clerk cannot read the room number, but the key is still in the drawer. A contractor gets a temporary badge that opens the service door for one shift and is returned at the end; the guest register never records it. A key-drop box accepts a key, lets the cleaner open the door, and keeps no impression of the cut.
Terraform's three mechanisms map onto those three behaviours, and each one fails differently. Confusing them ships a password to an artifact bucket.
Sensitive is a display flag. Marking a variable or output sensitive makes Terraform print (sensitive value) in plans, applies and human-readable output. The value is not removed: it stays in the plan file and in state, and JSON output returns it in cleartext. The flag has existed since Terraform 0.14 for variables and outputs, and 0.15 for provider-driven marks.
An ephemeral value exists for one operation. Terraform 1.10 introduced ephemeral input variables, ephemeral resources and ephemeral outputs from child modules. The value is available while Terraform evaluates configuration and calls providers, then it is gone, and it is omitted from both the plan file and the state file. That is stronger than redaction, but it is not storage: a CI environment, a -var argument or a variable file may still hold the source value.
A write-only argument belongs to the provider schema. Terraform 1.11 added the language capability, and the provider must opt in. Terraform passes the value during the operation and never writes it to plan or state. Unlike an ephemeral resource, a write-only argument accepts both ephemeral and ordinary values; using an ephemeral source is still the safer habit, because a literal in configuration is a secret in Git.
One sentence to keep them apart
Sensitive hides, ephemeral expires, write-only never lands in an artifact. Each protects a different moment: the screen, the run, or the stored record.
Figure 1 turns that into a selection path.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["A value must reach a provider"] --> B{"What must the artifact not contain?"}
B -->|"only the screen"| C["sensitive = true"]
B -->|"the value, after this run"| D{"Does the provider support a temporary route?"}
D -->|"ephemeral resource"| E["ephemeral block"]
D -->|"write-only argument"| F["*_wo plus *_wo_version"]
D -->|"neither"| G["External secret store read at runtime"]
C --> H["Plan and state still hold the value"]
E --> I["Omitted from plan and state"]
F --> J["Omitted from plan and state"]
G --> K["Terraform persists only a reference"]
I --> L{"Used in an ordinary argument?"}
L -->|"yes"| M["Plan error: not a write-only argument"]
L -->|"no"| N["Provider receives it during apply"]
J --> O{"Version argument incremented?"}
O -->|"no"| P["No plan diff to review"]
O -->|"yes"| Q["Provider updates the remote value"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class B,D,L,O primary;
class A,C,E,F,G,I,J,K secondary;
class N,Q ok;
class H,M,P danger;
The right-hand branches surprise people: an ephemeral value in an ordinary argument is a plan error, and a write-only value changed without a version bump produces no plan diff to review.
Figure 2 places the three semantics on opposite sides of the persistence boundary.
Read Figure 2 by row. Sensitive reaches the plan and the state, where the bytes remain readable to anyone with access. Ephemeral stops at the boundary. Write-only stops at the boundary too, though the provider may retain the secret on its side and Terraform may retain a version number on ours.
The table states the same comparison for a design review.
| Semantics | What Terraform retains | Plan file | State file | Minimum version |
|---|---|---|---|---|
| Plain argument | Everything | Value | Value | Any supported CLI |
sensitive | The value, flagged for display redaction | Value on disk, redacted on screen | Value | 0.14 for variables and outputs, 0.15 for provider schema marks |
| Ephemeral value | Nothing after the operation | Omitted | Omitted | Terraform 1.10 |
| Ephemeral resource | Nothing, because it has no state record | Omitted | Omitted | Terraform 1.10 plus a provider-defined ephemeral type |
| Write-only argument | The resource record without the value, plus a version counter if defined | (write-only attribute) on create, no diff on change | null for the argument | Terraform 1.11 plus a provider schema that marks the argument write-only |
The minimum-version column is not a suggestion. A configuration using an ephemeral declaration is rejected by 1.9, and a write-only argument is rejected by 1.10 even when the provider offers it. Upgrade the CLI before you change the configuration, or the error arrives at the worst moment.
Pass Ephemeral Variables Through Supported Contexts
An ephemeral variable is a delivery route, not a vault. It tells Terraform to accept a value at runtime and keep it out of the artifacts, but the value still comes from somewhere: a CI secret, an OIDC exchange that writes a short-lived token into the environment, or an operator at a prompt. Prefer the exchange in automation; a prompt leaves the value in shell history and the process list. A variable file is still a file on disk, and an ephemeral declaration does not delete it.
Declare the variable with both flags. sensitive keeps it out of logs and plan output; ephemeral keeps it out of plan and state.
The receiving context must support ephemerality. A value can travel through the places below, and each carries one condition: the destination must be ephemeral too.
| Context | Direction or role | Condition |
|---|---|---|
| Ephemeral variable | Runtime source into configuration | Declared with ephemeral = true; the source itself is not protected |
| Child module input | Parent to child | Child variable must be ephemeral |
| Child module output | Child to parent | Output must be ephemeral; the parent's reference inherits it |
| Write-only argument | Configuration to provider | Provider schema marks the argument write-only |
| Ephemeral resource block | Provider to configuration | Provider publishes the ephemeral type |
| Provider block | Authentication for the run | Accepts an ephemeral value; it is used before resources exist |
| Locals block | Intermediate expression | Result inherits ephemerality and cannot launder it |
| Provisioner or connection | Configuration to provisioner | Supported for the duration of that step |
| Root output | Configuration to consumer | Rejected |
count, for_each or address | Planning decision | Rejected: the decision must survive into state |
Root outputs cannot be ephemeral
The root module is the exception. Terraform rejects an ephemeral output there, because a root output exists to be stored and read by other configurations and remote-state consumers. Publish a reference or a path instead, and let the consumer fetch the secret from the system that owns it.
Two more constraints follow. An ephemeral value cannot decide count, for_each or a resource address, because those decisions are fixed during planning and must survive into state. An ephemeral resource is deferred to apply when its arguments are unknown during planning, so it cannot unblock work that a plan must finish.
The panel shows the full route. An ephemeral token configures the provider, a child module generates a password, and the parent consumes its ephemeral output in a write-only argument.
Design-only, not a recorded lab. The configuration targets Terraform 1.17.1, hashicorp/random 3.9.1 and hashicorp/vault 5.13.0, checked against provider schemas on 5 November 2026. It needs a disposable directory and registry access; no cloud account.
Figure 3 shows the route and the places where it stops.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["CI secret or OIDC exchange"] --> B["ephemeral variable"]
B --> C{"Destination"}
C -->|"provider block"| D["Provider authenticated"]
C -->|"child module input"| E["ephemeral child variable"]
C -->|"write-only argument"| F["Resource receives value"]
E --> G["ephemeral child output"]
G --> F
F --> H["Apply completes, value discarded"]
C -->|"root output"| I["Error: ephemeral outputs not allowed"]
C -->|"ordinary argument"| J["Error: invalid use of ephemeral value"]
C -->|"count or for_each"| K["Error: value must be known and persist"]
D --> H
H --> L{"Artifacts inspected"}
L -->|"plan file"| M["No ephemeral value"]
L -->|"state file"| N["No ephemeral value"]
L -->|"job environment"| O["Source value may remain"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class C,K,L primary;
class A,B,D,E,F,G,H,M,N secondary;
class I,J danger;
class O warn;
The left column is the supported path; the three error branches are the language refusing to pretend. The last branch is the honest limitation: TF_VAR_vault_token is still an environment variable, and an ephemeral declaration only controls what Terraform writes.
Use an Ephemeral Resource Only When the Provider Supports It
An ephemeral resource is a provider-defined type, not a Terraform primitive. The random provider publishes a password type, and the Vault provider publishes a read-only secret variant. There is no generic ephemeral secret block, and no way to promote a data source into one. Check the provider schema before designing around it.
Inspect the schema, not the registry blurb. Terraform's schema JSON has a separate ephemeral_resource_schemas section, and the registry marks the type as an ephemeral resource. If the type is absent, the provider cannot give you the guarantee; a data source is the wrong substitute because its result is stored in state like any other read.
The lifecycle has three steps. Terraform opens the resource when something needs its result, asks the provider to renew it if the run lasts longer than the remote lease allows, and closes it after the dependent providers finish the current phase. A Vault ephemeral resource is the clearest example: opening obtains a lease and returns the secret, renewal extends the lease, and closing revokes it immediately rather than waiting for the TTL.
That lifecycle creates costs that state-backed resources do not have. Every plan or apply that needs the value opens a new lease, so a CI system that plans on every pull request can exhaust a rate limit or an issuance quota. Renewal is not universal; a provider that cannot extend a lease may fail a long apply rather than silently expire. A failed close leaves the lease alive until its TTL, a cleanup item in the provider.
The constraints are the ones from the previous section, applied to a resource rather than a variable. You can reference the result in a write-only argument, another ephemeral block, a local, an ephemeral variable, a child module's ephemeral output, provider configuration, or a provisioner. You cannot store it, output it from the root, or use it to choose an address. Ephemeral resources also have no drift story: there is no state record to compare, so each run reads or generates the value afresh. That is usually the point, but it means a plan cannot tell you that the remote secret changed since yesterday.
A lease, not a secret manager
Use an ephemeral resource when the value is short-lived and the provider built the type. Each plan or apply that needs it opens a new lease, so the guarantee is freshness, not custody.
A Write-Only Argument Is Defined by the Provider Schema
A write-only argument is a property of one argument on one managed resource. The provider schema carries write_only: true, Terraform 1.11 and later honours it, and the provider promises to accept the value without returning it for storage. Nothing in your configuration can turn an ordinary argument into a write-only one.
Verify the flag in the provider schema. The schema is the only authority on whether an argument is write-only; an attribute name or a blog post is not.
The naming convention is *_wo for the value and *_wo_version for a counter, but both are conventions, not language rules. The provider defines whether a version argument exists and what it does. When it exists, Terraform stores the counter and can diff it. That solves the otherwise unsolvable problem: Terraform cannot see a change in a value it never stored, so without a counter, editing the secret produces no plan diff. Increment the counter to give the provider a signal that the value changed.
This is where write-only differs from an ephemeral variable in a way that matters at review time. A write-only argument accepts an ordinary value too. Passing a literal string works, which makes it easy to move a secret from state into a .tf file and call the problem solved. Use an ephemeral source, or accept that the repository is now the system of record.
Write-only protects the value, not the metadata
Terraform retains less, not nothing. The version counter, resource id, mount path or ARN, username, rotation timestamp and custom metadata may all be stored. The provider may also keep the secret in a versioned store on its side, which is what recovery needs and what a retention policy must cover. Write-only does not make the provider forget.
Finally, expect the provider to receive the write-only value on every operation, not only when the counter changes. The counter controls when an update is meaningful, but Terraform does not hold the old value to compare, so the provider's behaviour is the contract. Read the resource documentation for the exact rule rather than assuming one provider's pattern applies everywhere.
Inspect a Disposable Plan and State Without Publishing Them
The safe way to prove absence is to use a value that does not matter. Generate a synthetic canary with a distinctive prefix, such as P21-SYNTHETIC- followed by random characters, and never use a real credential for the test. A canary is searchable and harmless if it leaks.
Keep the whole exercise disposable and private. Restrict the directory to its owner, restrict any file you keep, and do not initialise a Git repository inside it. If you need a snapshot for comparison, copy it to a subdirectory you will delete.
Inspect with read-only commands and narrow filters. Print only the resource and the two or three attributes you need, never the full document.
| Command | What it returns | Printing it in full |
|---|---|---|
terraform show -json tfplan | Machine-readable plan document | Exposes every value the plan holds |
terraform show -json on state | Machine-readable state document | Exposes every value in state |
terraform providers schema -json | Types and attributes, not values | Safe: it describes the schema |
Do not enable TF_LOG for this exercise. Provider debug logs and Terraform's crash.log can contain request and response bodies from the failing operation, and a log file is an artifact with a longer life than the plan. If a provider returns an error that quotes the secret, treat the error text as sensitive too.
Search the artifacts for the canary after every step. A recursive text search over the directory, excluding the configuration file that legitimately contains the canary if you used a literal, is enough to prove that the value did not land in the new plan or the current state. A backup from before the change is expected to contain the old value; that is yesterday's problem, not a failure of this run. Then check the provider's own store to prove the value did arrive where it was supposed to. Absence in the current Terraform artifacts plus presence in the provider is the complete result; either one alone is inconclusive.
Figure 4 shows the two outcomes and the failure path that turns a disposable test into a permanent exposure.
The orange strip is the rule that outlives the lab. If an auditor needs evidence, record the command, the filter, the exit status and the date, not the artifact. A screenshot of a filtered result that prints only attribute names is evidence; the plan file is a liability.
Migrating Today Does Not Erase Yesterday’s Snapshots
Changing the configuration is the easy half. The old value is already in every artifact the pipeline touched: the current state, the .backup, versioned objects in the backend, saved plans in CI, hosted state versions, and any debugging copy. A write-only argument changes what the next snapshot contains. It does not reach backwards.
The migration is not the rotation. If the old secret is still valid at the provider, deleting copies of it buys nothing: anyone who kept one can still use it. The safe order is: move the value to a temporary route, apply, verify the provider accepts it, rotate to a new value with a version bump, then revoke the old credential. Revocation is the step that makes every historical copy worthless. Purge the artifacts afterwards, in whatever order your retention policy allows.
Versioned storage keeps every copy
Deleting the current state file is not deletion. Versioned S3 buckets, hosted backend state versions and backup appliances keep the previous object, and an object-lock policy can block removal until a retention date. Vault KV, AWS Secrets Manager and a database password history keep their own older versions. A migration that only changes Terraform leaves all of that intact.
Record the residual exposure instead of claiming it is gone. A short note is enough: the secret's identifier and purpose (never its value), where it was stored, when it appeared and when the credential was revoked, which copies were purged, which remain and why, the owner, and the next review date. That note is the difference between a cleanup and a story about a cleanup.
The lab proves the boundary with a local Vault server, a synthetic canary and a legacy snapshot that deliberately contains the value.
Prove the secret persistence boundary
Execution status: design-only. The sequence is written for Terraform 1.17.1, hashicorp/vault 5.13.0 and hashicorp/random 3.9.1, with a local Vault dev server. It was not executed as a recorded lab; every command below is a plan, not a claim that it ran.
Prerequisites. Terraform 1.17.1, the Vault CLI, jq, a disposable directory, and no cloud account. The dev server stores everything in memory and serves plain HTTP on loopback; never treat it as a production pattern.
# Terminal 1: in-memory dev server on loopback
vault server -dev -dev-root-token-id=root
# Lab terminal: point at it and create a synthetic canary
export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=root
export TF_VAR_synthetic_secret="P21-SYNTHETIC-$(openssl rand -hex 6)"
Minimal setup. The variable is only sensitive here: it feeds an ordinary argument, and marking it ephemeral would be a plan error.
terraform {
required_version = "1.17.1"
required_providers {
vault = {
source = "hashicorp/vault"
version = "5.13.0"
}
}
}
variable "synthetic_secret" {
type = string
sensitive = true
}
resource "vault_mount" "kvv2" {
path = "kvv2"
type = "kv"
options = { version = "2" }
}
resource "vault_kv_secret_v2" "lab" {
mount = vault_mount.kvv2.path
name = "p21-lab"
data_json = jsonencode({ password = var.synthetic_secret })
disable_read = true
custom_metadata {
max_versions = 2
}
}
| # | Action | Expected result |
|---|---|---|
| 1 | Run terraform init; filter the Vault resource's attributes for write_only == true | data_json_wo is flagged; data_json is not |
| 2 | Apply the legacy configuration; copy the state into snapshots/ with owner-only permissions | Yesterday's artifact: local only, never uploaded, deleted in step 9 |
| 3 | Search snapshots/ for the canary | A match in the state copy |
| 4 | Add ephemerality to the variable, switch to data_json_wo, set version 1, keep disable_read = true | The provider cannot read the secret back into data |
| 5 | Run terraform plan -out=tfplan; inspect the resource; apply | data_json_wo = (write-only attribute), no value |
| 6 | Filter current state for data_json, data_json_wo and the version; search the directory | null, null, 1; the automatic backup still has the canary |
| 7 | Read the secret back from Vault | The canary: the migration changed the artifact, not the remote value |
| 8 | Export a second canary, set the version to 2, apply | Version 2 current; version 1 still readable |
| 9 | Delete snapshots/, the backup and the plan; stop the server; write the exposure note | No local copy; the old version remains in Vault |
Expected observation. The canary is present in Vault and absent from the current state and plan. The saved snapshot and the automatic backup still contain it after the migration, and Vault's version history still contains it after rotation.
Failure checks. A match in the current state means the argument is not actually write-only; re-check the schema. A plan that shows no change after editing the secret means the version counter was not incremented. A 403 means the token lacks permission, and a connection error means the address is wrong. A 404 means the mount or secret name is wrong. A canary in the plan file means the plan was produced before the migration, not after it.
Cost dimensions. Zero cloud spend. The dev server uses local memory and CPU; the plan and state are kilobytes. The real cost is the discipline of using a synthetic value and deleting the directory.
Cleanup. Stop the Vault dev server, remove the lab directory, clear the Terraform and Vault environment variables, and close the shell so the canary is not retained in its history. On a shared machine, check the trash and any backup tool before declaring the copy gone.
Next in the Series
In Validation, Checks and Native Terraform Tests, we'll explore Choose the right failure mechanism and test behavior without mistaking a valid configuration for correct infrastructure.